home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / vibrant / vibwndws.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-05  |  129.9 KB  |  5,257 lines  |  [TEXT/R*ch]

  1. /*   vibwndws.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  vibwndws.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.45 $
  33. *
  34. * File Description: 
  35. *       Vibrant main, event loop, and window functions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49.  
  50. #ifdef WIN_MAC
  51. #include <Resources.h>
  52. #include <Scrap.h>
  53. /*#include <Strings.h>*/
  54. #include <Processes.h>
  55. #include <Events.h> /* keymap, dgg */
  56. #include <AppleEvents.h>
  57. #include <EPPC.h> /* kHighLevelEvent */
  58. #endif
  59.  
  60. #ifdef WIN_MAC
  61. #include <Resources.h>
  62. #ifndef Nlm_WindowTool
  63. #define Nlm_WindowTool  WindowPtr
  64. #endif
  65. #ifndef Nlm_PortTool
  66. #define Nlm_PortTool    GrafPtr
  67. #endif
  68. #ifndef Nlm_ShellTool
  69. #define Nlm_ShellTool   Nlm_Handle
  70. #endif
  71. #ifndef Nlm_MainTool
  72. #define Nlm_MainTool    Nlm_Handle
  73. #endif
  74. #endif
  75.  
  76. #ifdef WIN_MSWIN
  77. #ifndef Nlm_WindowTool
  78. #define Nlm_WindowTool  HWND
  79. #endif
  80. #ifndef Nlm_PortTool
  81. #define Nlm_PortTool    HDC
  82. #endif
  83. #ifndef Nlm_ShellTool
  84. #define Nlm_ShellTool   Nlm_Handle
  85. #endif
  86. #ifndef Nlm_MainTool
  87. #define Nlm_MainTool    Nlm_Handle
  88. #endif
  89. #endif
  90.  
  91. #ifdef WIN_MOTIF
  92. #include <Xm/DialogS.h>
  93. #ifndef Nlm_WindowTool
  94. #define Nlm_WindowTool  Widget
  95. #endif
  96. #ifndef Nlm_PortTool
  97. #define Nlm_PortTool    GC
  98. #endif
  99. #ifndef Nlm_ShellTool
  100. #define Nlm_ShellTool   Widget
  101. #endif
  102. #ifndef Nlm_MainTool
  103. #define Nlm_MainTool    Widget
  104. #endif
  105. #endif
  106.  
  107. typedef  struct  Nlm_windowdata {
  108.   Nlm_WindowTool   handle;
  109.   Nlm_ShellTool    shell;
  110.   Nlm_PortTool     port;
  111.   Nlm_MainTool     main;
  112.   Nlm_RecT         dragArea;
  113.   Nlm_RecT         growArea;
  114.   Nlm_RecT         zoomArea;
  115.   Nlm_WndActnProc  close;
  116.   Nlm_WndActnProc  activate;
  117.   Nlm_WndActnProc  deactivate;
  118.   Nlm_WndActnProc  resize;
  119.   Nlm_DisplaY      charDisplay;
  120.   Nlm_MenuBaR      menuBar;
  121.   Nlm_ButtoN       defaultButton;
  122.   Nlm_Boolean      notYetShown;
  123.   Nlm_Boolean      dying;
  124.   Nlm_CharPtr      title;
  125.   Nlm_VoidPtr      data;
  126.   Nlm_WndFreeProc  cleanup;
  127. } Nlm_WindowData;
  128.  
  129. typedef  struct  Nlm_windowrec {
  130.   Nlm_BoxRec      boxR;
  131.   Nlm_WindowData  window;
  132. } Nlm_WindowRec, PNTR Nlm_WndPtr;
  133.  
  134. Nlm_WindoW   Nlm_desktopWindow;
  135. Nlm_WindoW   Nlm_systemWindow;
  136.  
  137. Nlm_RecT     Nlm_screenRect;
  138.  
  139. Nlm_WindoW   Nlm_theWindow;
  140.  
  141. #ifdef WIN_MAC
  142. EventRecord  Nlm_currentEvent;
  143. #endif
  144.  
  145. #ifdef WIN_MSWIN
  146. WPARAM       Nlm_currentWParam;
  147. HINSTANCE    Nlm_currentHInst;
  148. LPARAM       Nlm_currentLParam;
  149. MSG          Nlm_currentMssg;
  150. int          Nlm_currentId;
  151. HWND         Nlm_currentHwndCtl;
  152. UINT         Nlm_currentCode;
  153. int          Nlm_currentPos;
  154. #if  defined(DCLAP) 
  155. /* for TranslateAccelerator == MenuKey */
  156. HWND         Nlm_menuHwnd = NULL;
  157. #endif
  158. #if  defined(DCLAP) && !defined(WIN16) 
  159. extern HACCEL    Nlm_hAccel;
  160. #endif
  161. #endif
  162.  
  163. #ifdef WIN_MOTIF
  164. XEvent        Nlm_currentEvent;
  165. XtAppContext  Nlm_appContext;
  166. XmFontList    Nlm_XfontList;
  167. Widget        Nlm_fileDialogShell;
  168.  
  169. int           argc;
  170. char          **argv;
  171. #endif
  172.  
  173. #ifdef DCLAP
  174.  
  175. /* currently only used in WIN_MOTIF, window creation */
  176. char  Nlm_appname[256];
  177.  
  178. #ifdef WIN_MOTIF
  179.  
  180. /* 
  181.      user can override these w/ .Xresources entry in form of
  182.   appname*resourcename: xxx
  183. -- or --
  184.   Vibrant*resourcename: xxx
  185. */
  186. static String colorXresources[] = {
  187.   "*Foreground:                 #000000000000",
  188.   "*XmScrollBar*Foreground:             #bfbfbfbfbfbf",
  189.   "*XmLabel*Foreground:                 #1d1d15155b5b",
  190.   "*XmToggleButton*Foreground:          #1d1d15155b5b",
  191.   "*XmPushButton*Foreground:            #5b5b00000000",
  192.  
  193.   "*Background:                         #ffffffffffff", /*cfcfcfcfcfcf = grey*/
  194.  
  195.   "*XmList*Background:             #bfbfbfbfbfbf",
  196.   "*XmText*Background:                 #bfbfbfbfbfbf",
  197.   "*XmSelectionBox*Background:         #bfbfbfbfbfbf",
  198.   "*XmMessageBox*Background:         #bfbfbfbfbfbf",
  199.   "*XmTextField*Background:         #9c9c9c9c9c9c",
  200.  
  201.   "*TopShadowColor:                     #e7e7e7e7e7e7",
  202.   "*XmList*TopShadowColor:              #e7e7e7e7e7e7",
  203.   "*XmText*TopShadowColor:              #e7e7e7e7e7e7",
  204.   "*XmSelectionBox*TopShadowColor:      #e7e7e7e7e7e7",
  205.   "*XmMessageBox*TopShadowColor:        #e7e7e7e7e7e7",
  206.   
  207.   "*TroughColor:     #646464646464",
  208.   "*SelectColor:            #ffffffff0000",
  209.   "*HighlightColor:        #bfbfbfbfbfbf",
  210.   NULL,
  211. };
  212.  
  213. static String bwXresources[] = {
  214.   "*Foreground:  black",
  215.   "*Background:  white",
  216.   NULL,
  217. };
  218.  
  219. #endif
  220.  
  221. #endif  /* DCLAP */
  222.  
  223.  
  224. Nlm_WindowTool  Nlm_currentWindowTool;
  225.  
  226. static Nlm_GphPrcsPtr  gphprcsptr = NULL;
  227.  
  228. static Nlm_GphPrcsPtr  documentProcs;
  229. static Nlm_GphPrcsPtr  fixedProcs;
  230. static Nlm_GphPrcsPtr  frozenProcs;
  231. static Nlm_GphPrcsPtr  roundProcs;
  232. static Nlm_GphPrcsPtr  alertProcs;
  233. static Nlm_GphPrcsPtr  modalProcs;
  234. static Nlm_GphPrcsPtr  floatingProcs;
  235. static Nlm_GphPrcsPtr  shadowProcs;
  236. static Nlm_GphPrcsPtr  plainProcs;
  237. static Nlm_GphPrcsPtr  desktopProcs;
  238. static Nlm_GphPrcsPtr  systemProcs;
  239.  
  240. static Nlm_Boolean     quitProgram;
  241. static Nlm_Boolean     getArgsBoxUp;
  242. static Nlm_Boolean     getArgsOk;
  243.  
  244. static Nlm_WindoW      recentWindow = NULL;
  245. static Nlm_WindowData  recentWindowData;
  246.  
  247. static Nlm_WindoW      chosenWindow;
  248. static Nlm_WindoW      frontWindow;
  249. static Nlm_WindoW      theActiveWindow;
  250.  
  251. static Nlm_WindoW      dyingWindow;
  252. static Nlm_RecT        screenBitBounds;
  253. static Nlm_Boolean     inNotice;
  254.  
  255. static Nlm_VoidProc    timerAction;
  256. static Nlm_KeyProc     keyAction;
  257.  
  258. #ifdef WIN_MAC
  259. static Cursor       cross;
  260. static Cursor       iBeam;
  261. static Cursor       plus;
  262. static Cursor       watch;
  263. static Nlm_Int4     lastTimerTime;
  264. static Nlm_Boolean  hasColorQD = FALSE;
  265. static Str255       apName;
  266. static Handle       apParam;
  267. static short        apRefNum;
  268. #endif
  269.  
  270. #ifdef WIN_MSWIN
  271. static HCURSOR       currentCursor;
  272. static UINT          timerID;
  273. static Nlm_Char      windowclass [32];
  274. static int           discard_count = 0;
  275. static LRESULT       mainwndrsult;
  276. static Nlm_Boolean   handlechar;
  277. #endif
  278.  
  279. #ifdef WIN_MOTIF
  280. static Cursor        currentCursor;
  281. static Cursor        arrow;
  282. static Cursor        cross;
  283. static Cursor        iBeam;
  284. static Cursor        plus;
  285. static Cursor        watch;
  286. static XFontStruct   *font;
  287. static XtIntervalId  windowTimer;
  288. static GC            firstGC;
  289. #ifdef DCLAP
  290.  int           statargc;
  291.  char          **statargv;
  292. #else
  293. static int           statargc;
  294. static char          **statargv;
  295. #endif
  296. #endif
  297.  
  298. static void Nlm_LoadWindowData (Nlm_WindoW w, Nlm_WindowTool hdl,
  299.                                 Nlm_ShellTool shl, Nlm_PortTool prt,
  300.                                 Nlm_MainTool man, Nlm_RectPtr drag,
  301.                                 Nlm_RectPtr grow, Nlm_RectPtr zoom,
  302.                                 Nlm_WndActnProc closeProc, Nlm_WndActnProc actProc,
  303.                                 Nlm_WndActnProc deactProc, Nlm_WndActnProc resiz,
  304.                                 Nlm_DisplaY charDisp, Nlm_MenuBaR mnuBar,
  305.                                 Nlm_ButtoN dfltBtn, Nlm_Boolean notYet,
  306.                                 Nlm_Boolean die, Nlm_CharPtr ttl,
  307.                                 Nlm_VoidPtr dat, Nlm_WndFreeProc cln)
  308.  
  309. {
  310.   Nlm_WindowData  PNTR wdptr;
  311.   Nlm_WndPtr      wp;
  312.  
  313.   if (w != NULL) {
  314.     wp = (Nlm_WndPtr) Nlm_HandLock (w);
  315.     wdptr = &(wp->window);
  316.     wdptr->handle = hdl;
  317.     wdptr->shell = shl;
  318.     wdptr->port = prt;
  319.     wdptr->main = man;
  320.     if (drag != NULL) {
  321.       wdptr->dragArea = *drag;
  322.     } else {
  323.       Nlm_LoadRect (&(wdptr->dragArea), 0, 0, 0, 0);
  324.     }
  325.     if (grow != NULL) {
  326.       wdptr->growArea = *grow;
  327.     } else {
  328.       Nlm_LoadRect (&(wdptr->growArea), 0, 0, 0, 0);
  329.     }
  330.     if (zoom != NULL) {
  331.       wdptr->zoomArea = *zoom;
  332.     } else {
  333.       Nlm_LoadRect (&(wdptr->zoomArea), 0, 0, 0, 0);
  334.     }
  335.     wdptr->close = closeProc;
  336.     wdptr->activate = actProc;
  337.     wdptr->deactivate = deactProc;
  338.     wdptr->resize = resiz;
  339.     wdptr->charDisplay = charDisp;
  340.     wdptr->menuBar = mnuBar;
  341.     wdptr->defaultButton = dfltBtn;
  342.     wdptr->notYetShown = notYet;
  343.     wdptr->dying = die;
  344.     wdptr->title = ttl;
  345.     wdptr->data = dat;
  346.     wdptr->cleanup = cln;
  347.     Nlm_HandUnlock (w);
  348.     recentWindow = NULL;
  349.   }
  350. }
  351.  
  352. static void Nlm_SetWindowData (Nlm_WindoW w, Nlm_WindowData * wdata)
  353.  
  354. {
  355.   Nlm_WndPtr  wp;
  356.  
  357.   if (w != NULL && wdata != NULL) {
  358.     wp = (Nlm_WndPtr) Nlm_HandLock (w);
  359.     wp->window = *wdata;
  360.     Nlm_HandUnlock (w);
  361.     recentWindow = w;
  362.     recentWindowData = *wdata;
  363.   }
  364. }
  365.  
  366. static void Nlm_GetWindowData (Nlm_WindoW w, Nlm_WindowData * wdata)
  367.  
  368. {
  369.   Nlm_WndPtr  wp;
  370.  
  371.   if (w != NULL && wdata != NULL) {
  372.     if (w == recentWindow && NLM_RISKY) {
  373.       *wdata = recentWindowData;
  374.     } else {
  375.       wp = (Nlm_WndPtr) Nlm_HandLock (w);
  376.       *wdata = wp->window;
  377.       Nlm_HandUnlock (w);
  378.       recentWindow = w;
  379.       recentWindowData = *wdata;
  380.     }
  381.   }
  382. }
  383.  
  384. static Nlm_WindowTool Nlm_GetWindowPtr (Nlm_WindoW w)
  385.  
  386. {
  387.   Nlm_WindowTool  rsult;
  388.   Nlm_WindowData  wdata;
  389.  
  390.   rsult = NULL;
  391.   if (w != NULL) {
  392.     Nlm_GetWindowData (w, &wdata);
  393.     rsult = wdata.handle;
  394.   }
  395.   return rsult;
  396. }
  397.  
  398. extern Nlm_ShellTool Nlm_GetWindowShell (Nlm_WindoW w)
  399.  
  400. {
  401.   Nlm_ShellTool   rsult;
  402.   Nlm_WindowData  wdata;
  403.  
  404.   rsult = NULL;
  405.   if (w != NULL) {
  406.     Nlm_GetWindowData (w, &wdata);
  407.     rsult = wdata.shell;
  408.   }
  409.   return rsult;
  410. }
  411.  
  412. static Nlm_PortTool Nlm_GetWindowPort (Nlm_WindoW w)
  413.  
  414. {
  415.   Nlm_PortTool    rsult;
  416.   Nlm_WindowData  wdata;
  417.  
  418.   rsult = NULL;
  419.   if (w != NULL) {
  420.     Nlm_GetWindowData (w, &wdata);
  421.     rsult = wdata.port;
  422.   }
  423.   return rsult;
  424. }
  425.  
  426. static Nlm_MainTool Nlm_GetWindowMain (Nlm_WindoW w)
  427.  
  428. {
  429.   Nlm_MainTool    rsult;
  430.   Nlm_WindowData  wdata;
  431.  
  432.   rsult = NULL;
  433.   if (w != NULL) {
  434.     Nlm_GetWindowData (w, &wdata);
  435.     rsult = wdata.main;
  436.   }
  437.   return rsult;
  438. }
  439.  
  440. #ifdef DCLAP
  441. extern void Nlm_SetAppWindow( Nlm_WindoW w)
  442. {
  443. #ifdef WIN_MSWIN
  444.   Nlm_menuHwnd= Nlm_GetWindowPtr(w);
  445. #endif
  446. }
  447. #endif
  448.  
  449. extern void Nlm_SetWindowCharDisplay (Nlm_WindoW w, Nlm_DisplaY d)
  450.  
  451. {
  452.   Nlm_WindowData  wdata;
  453.  
  454.   if (w != NULL) {
  455.     Nlm_GetWindowData (w, &wdata);
  456.     wdata.charDisplay = d;
  457.     Nlm_SetWindowData (w, &wdata);
  458.   }
  459. }
  460.  
  461. extern Nlm_DisplaY Nlm_GetWindowCharDisplay (Nlm_WindoW w)
  462.  
  463. {
  464.   Nlm_DisplaY     rsult;
  465.   Nlm_WindowData  wdata;
  466.  
  467.   rsult = NULL;
  468.   if (w != NULL) {
  469.     Nlm_GetWindowData (w, &wdata);
  470.     rsult = wdata.charDisplay;
  471.   }
  472.   return rsult;
  473. }
  474.  
  475. extern void Nlm_SetWindowMenuBar (Nlm_WindoW w, Nlm_MenuBaR mb)
  476.  
  477. {
  478.   Nlm_WindowData  wdata;
  479.  
  480.   if (w != NULL) {
  481.     Nlm_GetWindowData (w, &wdata);
  482.     wdata.menuBar = mb;
  483.     Nlm_SetWindowData (w, &wdata);
  484.   }
  485. }
  486.  
  487. extern Nlm_MenuBaR Nlm_GetWindowMenuBar (Nlm_WindoW w)
  488.  
  489. {
  490.   Nlm_MenuBaR     rsult;
  491.   Nlm_WindowData  wdata;
  492.  
  493.   rsult = NULL;
  494.   if (w != NULL) {
  495.     Nlm_GetWindowData (w, &wdata);
  496.     rsult = wdata.menuBar;
  497.   }
  498.   return rsult;
  499. }
  500.  
  501. extern void Nlm_SetWindowDefaultButton (Nlm_WindoW w, Nlm_ButtoN b)
  502.  
  503. {
  504.   Nlm_WindowData  wdata;
  505.  
  506.   if (w != NULL) {
  507.     Nlm_GetWindowData (w, &wdata);
  508.     wdata.defaultButton = b;
  509.     Nlm_SetWindowData (w, &wdata);
  510.   }
  511. }
  512.  
  513. extern Nlm_ButtoN Nlm_GetWindowDefaultButton (Nlm_WindoW w)
  514.  
  515. {
  516.   Nlm_ButtoN      rsult;
  517.   Nlm_WindowData  wdata;
  518.  
  519.   rsult = NULL;
  520.   if (w != NULL) {
  521.     Nlm_GetWindowData (w, &wdata);
  522.     rsult = wdata.defaultButton;
  523.   }
  524.   return rsult;
  525. }
  526.  
  527. static void Nlm_SetNotYetShown (Nlm_WindoW w, Nlm_Boolean notYet)
  528.  
  529. {
  530.   Nlm_WindowData  wdata;
  531.  
  532.   if (w != NULL) {
  533.     Nlm_GetWindowData (w, &wdata);
  534.     wdata.notYetShown = notYet;
  535.     Nlm_SetWindowData (w, &wdata);
  536.   }
  537. }
  538.  
  539. extern Nlm_Boolean Nlm_WindowHasBeenShown (Nlm_WindoW w)
  540.  
  541. {
  542.   Nlm_Boolean     rsult;
  543.   Nlm_WindowData  wdata;
  544.  
  545.   rsult = FALSE;
  546.   if (w != NULL) {
  547.     Nlm_GetWindowData (w, &wdata);
  548.     rsult = (Nlm_Boolean) (! wdata.notYetShown);
  549.   }
  550.   return rsult;
  551. }
  552.  
  553. static void Nlm_SetWindowDying (Nlm_WindoW w, Nlm_Boolean die)
  554.  
  555. {
  556.   Nlm_WindowData  wdata;
  557.  
  558.   if (w != NULL) {
  559.     Nlm_GetWindowData (w, &wdata);
  560.     wdata.dying = die;
  561.     Nlm_SetWindowData (w, &wdata);
  562.   }
  563. }
  564.  
  565. extern Nlm_Boolean Nlm_IsWindowDying (Nlm_WindoW w)
  566.  
  567. {
  568.   Nlm_Boolean     rsult;
  569.   Nlm_WindowData  wdata;
  570.  
  571.   rsult = FALSE;
  572.   if (w != NULL) {
  573.     Nlm_GetWindowData (w, &wdata);
  574.     rsult = wdata.dying;
  575.   }
  576.   return rsult;
  577. }
  578.  
  579. extern Nlm_WindoW Nlm_GetParentWindow (Nlm_GraphiC a)
  580.  
  581. {
  582.   Nlm_GraphiC  g;
  583.   Nlm_GraphiC  p;
  584.  
  585.   g = a;
  586.   if (a != NULL) {
  587.     p = Nlm_GetParent (g);
  588.     while (p != NULL) {
  589.       g = p;
  590.       p = Nlm_GetParent (g);
  591.     }
  592.   }
  593.   return (Nlm_WindoW) g;
  594. }
  595.  
  596. extern Nlm_WindoW Nlm_ParentWindow (Nlm_Handle a)
  597.  
  598. {
  599.   return Nlm_GetParentWindow ((Nlm_GraphiC) a);
  600. }
  601.  
  602. extern Nlm_WindowTool Nlm_ParentWindowPtr (Nlm_GraphiC a)
  603.  
  604. {
  605.   Nlm_WindowTool  rsult;
  606.   Nlm_WindoW      w;
  607.  
  608.   rsult = NULL;
  609.   if (a != NULL) {
  610.     w = Nlm_GetParentWindow (a);
  611.     rsult = Nlm_GetWindowPtr (w);
  612.   }
  613.   return rsult;
  614. }
  615.  
  616. extern Nlm_PortTool Nlm_ParentWindowPort (Nlm_GraphiC a)
  617.  
  618. {
  619.   Nlm_PortTool  rsult;
  620.   Nlm_WindoW    w;
  621.  
  622.   rsult = NULL;
  623.   if (a != NULL) {
  624.     w = Nlm_GetParentWindow (a);
  625.     rsult = Nlm_GetWindowPort (w);
  626.   }
  627.   return rsult;
  628. }
  629.  
  630. extern Nlm_MainTool Nlm_ParentWindowMain (Nlm_GraphiC a)
  631.  
  632. {
  633.   Nlm_MainTool  rsult;
  634.   Nlm_WindoW    w;
  635.  
  636.   rsult = NULL;
  637.   if (a != NULL) {
  638.     w = Nlm_GetParentWindow (a);
  639.     rsult = Nlm_GetWindowMain (w);
  640.   }
  641.   return rsult;
  642. }
  643.  
  644. extern Nlm_ShellTool Nlm_ParentWindowShell (Nlm_GraphiC a)
  645.  
  646. {
  647.   Nlm_ShellTool  rsult;
  648.   Nlm_WindoW     w;
  649.  
  650.   rsult = NULL;
  651.   if (a != NULL) {
  652.     w = Nlm_GetParentWindow (a);
  653.     rsult = Nlm_GetWindowShell (w);
  654.   }
  655.   return rsult;
  656. }
  657.  
  658. extern Nlm_WindoW Nlm_SavePortIfNeeded (Nlm_GraphiC a, Nlm_Boolean savePort)
  659.  
  660. {
  661.   Nlm_WindoW  newwindow;
  662.   Nlm_WindoW  oldwindow;
  663.   Nlm_WindoW  rsult;
  664.  
  665.   rsult = NULL;
  666.   if (a != NULL && savePort) {
  667.     savePort = Nlm_GetAllParentsVisible (a);
  668.     if (savePort) {
  669.       oldwindow = Nlm_CurrentWindow ();
  670.       newwindow = Nlm_GetParentWindow (a);
  671.       savePort = (Nlm_Boolean) (oldwindow != newwindow);
  672.       if (savePort) {
  673.         Nlm_UseWindow (newwindow);
  674.         rsult = oldwindow;
  675.       }
  676.     }
  677.   }
  678.   return rsult;
  679. }
  680.  
  681. extern Nlm_WindoW Nlm_SavePort (Nlm_Handle a)
  682.  
  683. {
  684.   return Nlm_SavePortIfNeeded ((Nlm_GraphiC) a, TRUE);
  685. }
  686.  
  687. extern void Nlm_RestorePort (Nlm_WindoW w)
  688.  
  689. {
  690. #ifndef DCLAP
  691.     /* !! dclap doesn't want to be redrawing all over the place like this does ! */
  692.   Nlm_Update ();
  693. #endif
  694.   if (w != NULL) {
  695.     Nlm_UseWindow (w);
  696.   }
  697. }
  698.  
  699. extern void Nlm_SetClose (Nlm_WindoW w, Nlm_WndActnProc cls)
  700.  
  701. {
  702.   Nlm_WindowData  wdata;
  703.  
  704.   if (w != NULL) {
  705.     Nlm_GetWindowData (w, &wdata);
  706.     wdata.close = cls;
  707.     Nlm_SetWindowData (w, &wdata);
  708.   }
  709. }
  710.  
  711. extern void Nlm_SetActivate (Nlm_WindoW w, Nlm_WndActnProc act)
  712.  
  713. {
  714.   Nlm_WindowData  wdata;
  715.  
  716.   if (w != NULL) {
  717.     Nlm_GetWindowData (w, &wdata);
  718.     wdata.activate = act;
  719.     Nlm_SetWindowData (w, &wdata);
  720.   }
  721. }
  722.  
  723. extern void Nlm_SetDeactivate (Nlm_WindoW w, Nlm_WndActnProc deact)
  724.  
  725. {
  726.   Nlm_WindowData  wdata;
  727.  
  728.   if (w != NULL) {
  729.     Nlm_GetWindowData (w, &wdata);
  730.     wdata.deactivate = deact;
  731.     Nlm_SetWindowData (w, &wdata);
  732.   }
  733. }
  734.  
  735. extern void Nlm_SetResize (Nlm_WindoW w, Nlm_WndActnProc resiz)
  736.  
  737. {
  738.   Nlm_WindowData  wdata;
  739.  
  740.   if (w != NULL) {
  741.     Nlm_GetWindowData (w, &wdata);
  742.     wdata.resize = resiz;
  743.     Nlm_SetWindowData (w, &wdata);
  744.   }
  745. }
  746.  
  747. extern void Nlm_SetWindowExtra (Nlm_WindoW w, Nlm_VoidPtr data, Nlm_WndFreeProc cleanup)
  748.  
  749. {
  750.   Nlm_WindowData  wdata;
  751.  
  752.   if (w != NULL) {
  753.     Nlm_GetWindowData (w, &wdata);
  754.     wdata.data = data;
  755.     wdata.cleanup = cleanup;
  756.     Nlm_SetWindowData (w, &wdata);
  757.   }
  758. }
  759.  
  760. extern Nlm_VoidPtr Nlm_GetWindowExtra (Nlm_WindoW w)
  761.  
  762. {
  763.   Nlm_WindowData  wdata;
  764.  
  765.   if (w != NULL) {
  766.     Nlm_GetWindowData (w, &wdata);
  767.     return wdata.data;
  768.   } else {
  769.     return NULL;
  770.   }
  771. }
  772.  
  773. static void Nlm_ClearKeys (void)
  774.  
  775. {
  776.   Nlm_cmmdKey = FALSE;
  777.   Nlm_ctrlKey = FALSE;
  778.   Nlm_optKey = FALSE;
  779.   Nlm_shftKey = FALSE;
  780.   Nlm_dblClick = FALSE;
  781. }
  782.  
  783. static Nlm_WindoW Nlm_FindWindowRec (Nlm_WindowTool wptr)
  784.  
  785. {
  786.   Nlm_WindoW      w;
  787. #ifdef WIN_MAC
  788.   Nlm_WindowData  wdata;
  789. #endif
  790.  
  791. #ifdef WIN_MAC
  792.   Nlm_GetWindowData (Nlm_systemWindow, &wdata);
  793.   wdata.handle = wptr;
  794.   Nlm_SetWindowData (Nlm_systemWindow, &wdata);
  795. #endif
  796.   w = Nlm_desktopWindow;
  797.   while (w != NULL && Nlm_ParentWindowPtr ((Nlm_GraphiC) w) != wptr) {
  798.     w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  799.   }
  800.   if (w == NULL) {
  801.     w = Nlm_desktopWindow;
  802.   }
  803.   return w;
  804. }
  805.  
  806. static void Nlm_SetWindowTitle (Nlm_GraphiC w, Nlm_Int2 item,
  807.                                 Nlm_CharPtr title, Nlm_Boolean savePort)
  808.  
  809.  
  810. {
  811.   Nlm_Char        temp [256];
  812.   Nlm_WindowTool  wptr;
  813. #ifdef WIN_MOTIF
  814.   Nlm_ShellTool   shl;
  815.   Nlm_WindowData  wdata;
  816. #endif
  817.  
  818.   wptr = Nlm_ParentWindowPtr (w);
  819.   Nlm_StringNCpy (temp, title, sizeof (temp));
  820. #ifdef WIN_MAC
  821.   Nlm_CtoPstr (temp);
  822.   SetWTitle (wptr, (StringPtr) temp);
  823. #endif
  824. #ifdef WIN_MSWIN
  825.   SetWindowText (wptr, temp);
  826. #endif
  827. #ifdef WIN_MOTIF
  828.   shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  829.   XtVaSetValues (shl, XmNtitle, temp, NULL);
  830.   XSync (Nlm_currentXDisplay, FALSE);
  831.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  832.   if (wdata.title != NULL) {
  833.     wdata.title = (Nlm_CharPtr) Nlm_MemFree (wdata.title);
  834.   }
  835.   wdata.title = Nlm_StringSave (title);
  836.   Nlm_SetWindowData ((Nlm_WindoW) w, &wdata);
  837. #endif
  838. }
  839.  
  840. static void Nlm_GetWindowTitle (Nlm_GraphiC w, Nlm_Int2 item,
  841.                                 Nlm_CharPtr title, Nlm_sizeT maxsize)
  842.  
  843. {
  844.   Nlm_Char        temp [256];
  845.   Nlm_WindowTool  wptr;
  846. #ifdef WIN_MOTIF
  847.   Nlm_WindowData  wdata;
  848. #endif
  849.  
  850.   wptr = Nlm_ParentWindowPtr (w);
  851.   temp [0] = '\0';
  852. #ifdef WIN_MAC
  853.   GetWTitle (wptr, (StringPtr) temp);
  854.   Nlm_PtoCstr (temp);
  855. #endif
  856. #ifdef WIN_MSWIN
  857.   GetWindowText (wptr, temp, sizeof (temp));
  858. #endif
  859. #ifdef WIN_MOTIF
  860.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  861.   Nlm_StringNCpy (temp, wdata.title, sizeof (temp));
  862. #endif
  863.   Nlm_StringNCpy (title, temp, maxsize);
  864. }
  865.  
  866. static Nlm_WindoW Nlm_MakeWindowLink (Nlm_RectPtr r, Nlm_Int2 recordSize,
  867.                                       Nlm_GphPrcs PNTR classPtr)
  868.  
  869. {
  870.   Nlm_GraphiC  n;
  871.   Nlm_WindoW   w;
  872.  
  873.   w = (Nlm_WindoW) Nlm_HandNew (recordSize);
  874.   if (w != NULL) {
  875.     n = Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  876.     Nlm_LoadGraphicData ((Nlm_GraphiC) w, n, NULL, NULL, NULL,
  877.                          classPtr, NULL, r, TRUE, FALSE);
  878.     if (Nlm_nextIdNumber < 32767) {
  879.       Nlm_nextIdNumber++;
  880.     }
  881.     Nlm_SetNext ((Nlm_GraphiC) Nlm_desktopWindow, (Nlm_GraphiC) w);
  882.   }
  883.   return w;
  884. }
  885.  
  886. #ifdef WIN_MAC
  887. extern void Nlm_SetUpdateRegion (WindowPtr wptr)
  888.  
  889. {
  890.   RgnPtr  rptr;
  891.  
  892.   if (wptr != NULL) {
  893.     CopyRgn (wptr->visRgn, (Nlm_RgnTool) Nlm_updateRgn);
  894.     HLock ((Handle) Nlm_updateRgn);
  895.     rptr = (RgnPtr) *((Handle) Nlm_updateRgn);
  896.     Nlm_RectToolToRecT (&(rptr->rgnBBox), &Nlm_updateRect);
  897.     HUnlock ((Handle) Nlm_updateRgn);
  898.   }
  899. }
  900. #endif
  901.  
  902. #ifdef WIN_MOTIF
  903. void WindowCloseCallback (Widget wd, XtPointer client_data, XtPointer call_data)
  904.  
  905. {
  906.   Nlm_WndActnProc  cls;
  907.   Nlm_WindoW       w;
  908.   Nlm_WindowData   wdata;
  909.  
  910.   w = (Nlm_WindoW) client_data;
  911.   Nlm_GetWindowData (w, &wdata);
  912.   cls = wdata.close;
  913.   if (cls != NULL) {
  914.     cls (w);
  915.   }
  916. }
  917.  
  918. void WindowResizeCallback (Widget wd, XtPointer client_data,
  919.                            XEvent *ev, Boolean *contin)
  920.  
  921. {
  922.   XConfigureEvent  *event;
  923.   Nlm_RecT         r;
  924.   Nlm_WndActnProc  resize;
  925.   Nlm_RectTool     rtool;
  926.   Nlm_WindoW       w;
  927.   Nlm_WindowData   wdata;
  928.  
  929.   event = (XConfigureEvent *) ev;
  930.   if (event->type != ConfigureNotify) {
  931.     return;
  932.   }
  933.   w = (Nlm_WindoW) client_data;
  934.   Nlm_GetWindowData (w, &wdata);
  935.   rtool.x = event->x;
  936.   rtool.y = event->y;
  937.   rtool.width = event->width;
  938.   rtool.height = event->height;
  939.   Nlm_RectToolToRecT (&rtool, &r);
  940.   Nlm_SetRect ((Nlm_GraphiC) w, &r);
  941.   if (Nlm_WindowHasBeenShown (w) && Nlm_GetVisible ((Nlm_GraphiC) w)) {
  942.     resize = wdata.resize;
  943.     if (resize != NULL) {
  944.       resize (w);
  945.     }
  946.   }
  947. }
  948. #endif
  949.  
  950. #define DOCUMENT_STYLE 1
  951. #define FIXED_STYLE    2
  952. #define FROZEN_STYLE   3
  953. #define ROUND_STYLE    4
  954. #define ALERT_STYLE    5
  955. #define MODAL_STYLE    6
  956. #define FLOATING_STYLE 7
  957. #define SHADOW_STYLE   8
  958. #define PLAIN_STYLE    9
  959.  
  960. static void Nlm_NewWindow (Nlm_WindoW w, Nlm_Int2 type, Nlm_Int2 procID,
  961.                            Nlm_Boolean goAway, Nlm_CharPtr windowClass,
  962.                            Nlm_Uint4 style, Nlm_CharPtr title,
  963.                            Nlm_WndActnProc close, Nlm_WndActnProc resize)
  964.  
  965. {
  966.   Nlm_ShellTool   dlg;
  967.   Nlm_RecT        drag;
  968.   Nlm_RecT        grow;
  969.   Nlm_Int2        hsb;
  970.   Nlm_MainTool    man;
  971.   Nlm_Int2        margin;
  972.   Nlm_RecT        p;
  973.   Nlm_PortTool    prt;
  974.   Nlm_PoinT       pt;
  975.   Nlm_RecT        r;
  976.   Nlm_ShellTool   shl;
  977.   Nlm_Int2        spacing;
  978.   Nlm_Char        temp [256];
  979.   Nlm_CharPtr     ttl;
  980.   Nlm_Int2        vsb;
  981.   Nlm_WindowTool  wptr;
  982.   Nlm_RecT        zoom;
  983. #ifdef WIN_MAC
  984.   Nlm_WindowTool  behindNone;
  985.   Nlm_RectTool    rtool;
  986. #endif
  987. #ifdef WIN_MOTIF
  988.   Atom            atom;
  989.   Cardinal        n;
  990.   Arg             wargs [15];
  991.   int             screen_num;
  992. #endif
  993.  
  994.   if (title != NULL && title [0] != '\0') {
  995.     Nlm_StringNCpy (temp, title, sizeof (temp));
  996.   } else {
  997.     temp [0] = '\0';
  998.   }
  999. #ifdef WIN_MAC
  1000.   Nlm_CtoPstr (temp);
  1001. #endif
  1002.   Nlm_LoadRect (&r, 50, 50, 150, 150);
  1003. #ifdef WIN_MOTIF
  1004.   r = Nlm_screenRect;
  1005.   Nlm_InsetRect (&r, 50, 50);
  1006. #endif
  1007.   Nlm_GetRect ((Nlm_GraphiC) w, &p);
  1008.   margin = 10;
  1009.   spacing = 10;
  1010.   if (p.right < 0) {
  1011.     margin = -p.right;
  1012.   }
  1013.   if (p.bottom < 0) {
  1014.     spacing = -p.bottom;
  1015.   }
  1016.   if (p.right >= 0 || p.bottom >= 0) {
  1017.     r = p;
  1018.     r.bottom = r.top + r.bottom;
  1019.     r.right = r.left + r.right;
  1020.   }
  1021. #ifdef DCLAP
  1022.     /* general protection against too small window sizes */
  1023.     if (r.bottom - r.top < 20) r.bottom = r.top + 20;
  1024.   if (r.right - r.left < 20) r.right= r.left + 20;
  1025. #endif
  1026.   Nlm_LoadPt (&pt, margin, margin);
  1027.   shl = NULL;
  1028.   dlg = NULL;
  1029.   wptr = NULL;
  1030.   prt = NULL;
  1031.   man = NULL;
  1032.   ttl = NULL;
  1033.   hsb = 0;
  1034.   vsb = 0;
  1035. #ifdef WIN_MAC
  1036.   wptr = (Nlm_WindowTool) Nlm_MemNew (sizeof (WindowRecord));
  1037.   behindNone = (Nlm_WindowTool) (-1);
  1038.   TextFont (0);
  1039.   TextSize (0);
  1040.   Nlm_RecTToRectTool (&r, &rtool);
  1041.   if (close == NULL) {
  1042.     goAway = FALSE;
  1043.   }
  1044.   if (hasColorQD) {
  1045.     wptr = (WindowPtr) NewCWindow ((Ptr) wptr, &rtool, (StringPtr) temp,
  1046.                                    FALSE, procID,(Nlm_WindowTool) behindNone,
  1047.                                    goAway, 0);
  1048.   } else {
  1049.     wptr = NewWindow ((Ptr) wptr, &rtool, (StringPtr) temp, FALSE, procID,
  1050.                       (Nlm_WindowTool) behindNone, goAway, 0);
  1051.   }
  1052.   SetPort (wptr);
  1053.   Nlm_currentWindowTool = wptr;
  1054.   prt = (Nlm_PortTool) wptr;
  1055.   Nlm_SetUpdateRegion (wptr);
  1056.   PenNormal ();
  1057.   MoveTo (2, 10);
  1058.   if (hasColorQD) {
  1059.     GetForeColor (&Nlm_RGBforeColor);
  1060.     GetBackColor (&Nlm_RGBbackColor);
  1061.   }
  1062. #endif
  1063. #ifdef WIN_MSWIN
  1064.   if (close == NULL) {
  1065.     style &= ~WS_SYSMENU;
  1066.   }
  1067.   if (type == FLOATING_STYLE) {
  1068.     wptr = CreateWindowEx (WS_EX_TOPMOST, windowClass, temp, style,
  1069.                          r.left, r.top, r.right - r.left,
  1070.                          r.bottom - r.top, NULL, NULL,
  1071.                          Nlm_currentHInst, NULL);
  1072.   } else if (type == MODAL_STYLE) {
  1073.     wptr = CreateWindowEx (WS_EX_DLGMODALFRAME, windowClass, temp, style,
  1074.                          r.left, r.top, r.right - r.left,
  1075.                          r.bottom - r.top, NULL, NULL,
  1076.                          Nlm_currentHInst, NULL);
  1077.   } else {
  1078.     wptr = CreateWindow (windowClass, temp, style,
  1079.                          r.left, r.top, r.right - r.left,
  1080.                          r.bottom - r.top, NULL, NULL,
  1081.                          Nlm_currentHInst, NULL);
  1082.   }
  1083.   if (wptr != NULL) {
  1084.     SetProp (wptr, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) w);
  1085.   }
  1086.   prt = GetDC (wptr);
  1087.   Nlm_currentHDC = prt;
  1088.   Nlm_currentHWnd = wptr;
  1089. #endif
  1090. #ifdef WIN_MOTIF
  1091.   n = 0;
  1092.   XtSetArg (wargs[n], XmNtitle, temp); n++;
  1093.   XtSetArg (wargs[n], XmNx, (Position) r.left); n++;
  1094.   XtSetArg (wargs[n], XmNy, (Position) r.top); n++;
  1095.   XtSetArg (wargs[n], XmNdefaultFontList, Nlm_XfontList); n++;
  1096.   XtSetArg (wargs[n], XmNdeleteResponse, XmDO_NOTHING); n++;
  1097. #ifdef DCLAP
  1098.     /* we want to stick app name here, thru some new vibrant global var */  
  1099.   shl = XtAppCreateShell (Nlm_appname, (String) "Vibrant",
  1100.                           applicationShellWidgetClass,
  1101.                           Nlm_currentXDisplay, wargs, n);
  1102. #else
  1103.   shl = XtAppCreateShell ((String) NULL, (String) "Vibrant",
  1104.                           applicationShellWidgetClass,
  1105.                           Nlm_currentXDisplay, wargs, n);
  1106. #endif
  1107.   dlg = shl;
  1108.   if (dlg != NULL) {
  1109.     XtSetMappedWhenManaged (shl, FALSE);
  1110.     XtAddEventHandler (shl, StructureNotifyMask, FALSE,
  1111.                        WindowResizeCallback, (XtPointer) w);
  1112.     n = 0;
  1113.     XtSetArg (wargs[n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  1114.     XtSetArg (wargs[n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  1115.     XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  1116.     XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  1117.     XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  1118.     man = XmCreateMainWindow (dlg, (String) "", wargs, n);
  1119.     n = 0;
  1120.     XtSetArg (wargs[n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  1121.     XtSetArg (wargs[n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  1122.     XtSetArg (wargs[n], XmNbuttonFontList, Nlm_XfontList); n++;
  1123.     XtSetArg (wargs[n], XmNlabelFontList, Nlm_XfontList); n++;
  1124.     XtSetArg (wargs[n], XmNtextFontList, Nlm_XfontList); n++;
  1125.     XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  1126.     XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  1127.     XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  1128.     wptr = XmCreateBulletinBoard (man, (String) "", wargs, n);
  1129.  
  1130.     screen_num = DefaultScreen (Nlm_currentXDisplay);
  1131.     prt = Nlm_currentXGC;
  1132.     XtManageChild (man);
  1133.     XtManageChild (wptr);
  1134.     if (NLM_QUIET) {
  1135.       Nlm_currentXWindow = 0;
  1136.     } else {
  1137.       XtRealizeWidget (shl);
  1138.       Nlm_currentXWindow = XtWindow (shl);
  1139.     }
  1140.     atom = XmInternAtom (Nlm_currentXDisplay, "WM_DELETE_WINDOW", TRUE);
  1141.     if (atom != 0) {
  1142.       XmAddWMProtocolCallback (shl, atom, WindowCloseCallback, (XtPointer) w);
  1143.     }
  1144.   }
  1145.   if (temp [0] != '\0') {
  1146.     ttl = Nlm_StringSave (temp);
  1147.   }
  1148. #endif
  1149.   Nlm_currentWindowTool = wptr;
  1150.   r = screenBitBounds;
  1151.   Nlm_LoadRect (&drag, r.left + 4, r.top + 24, r.right - 4, r.bottom - 4);
  1152.   Nlm_LoadRect (&grow, r.left, r.top + 24, r.right, r.bottom);
  1153.   Nlm_LoadRect (&zoom, r.left + 4, r.top + 40, r.right - 4, r.bottom - 4);
  1154.   Nlm_LoadRect (&r, 0, 0, 0, 0);
  1155.  
  1156. #ifdef DCLAP
  1157. #ifdef WIN_MSWIN
  1158.   hsb = 6; vsb = 4;  /* dgg -- patch for mswin sizebar space */
  1159. #endif
  1160. #endif
  1161.  
  1162.   Nlm_LoadBoxData ((Nlm_BoX) w, pt, pt, pt, margin, margin,
  1163.                    margin + hsb, margin + vsb, spacing, spacing, 0, 0);
  1164.   Nlm_LoadWindowData (w, wptr, shl, prt, man, &drag, &grow, &zoom, close, NULL,
  1165.                       NULL, resize, NULL, NULL, NULL, TRUE, FALSE, ttl, NULL, NULL);
  1166. }
  1167.  
  1168. #ifdef WIN_MAC
  1169. static Nlm_WindoW Nlm_NextVisWindow (Nlm_WindoW w)
  1170.  
  1171. {
  1172.   WindowPeek  p;
  1173.   WindowPeek  q;
  1174.  
  1175.   if (w == Nlm_desktopWindow) {
  1176.     return Nlm_desktopWindow;
  1177.   } else {
  1178.     p = (WindowPeek) Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1179.     while (p != NULL) {
  1180.       q = p->nextWindow;
  1181.       if (q != NULL) {
  1182.         if (q->visible != 0) {
  1183.           p = NULL;
  1184.         } else {
  1185.           p = q;
  1186.         }
  1187.       } else {
  1188.         p = q;
  1189.       }
  1190.     }
  1191.     return Nlm_FindWindowRec ((Nlm_WindowTool) q);
  1192.   }
  1193. }
  1194. #endif
  1195.  
  1196. static void Nlm_RemoveWindow (Nlm_GraphiC w, Nlm_Boolean savePort)
  1197.  
  1198. {
  1199.   Nlm_WindoW     nxt;
  1200.   Nlm_WindoW     p;
  1201.   Nlm_WindoW     q;
  1202. #ifdef WIN_MOTIF
  1203.   Nlm_ShellTool  shl;
  1204. #endif
  1205.  
  1206.   if ((Nlm_WindoW) w != Nlm_desktopWindow && (Nlm_WindoW) w != Nlm_systemWindow) {
  1207.     q = Nlm_desktopWindow;
  1208.     p = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  1209.     while (p != NULL && p != (Nlm_WindoW) w) {
  1210.       q = p;
  1211.       p = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) p);
  1212.     }
  1213.     if (p != NULL) {
  1214. #ifdef WIN_MAC
  1215.       HideWindow (Nlm_GetWindowPtr ((Nlm_WindoW) w));
  1216.       Nlm_Update ();
  1217. #endif
  1218. #ifdef WIN_MSWIN
  1219.       ShowWindow (Nlm_GetWindowPtr ((Nlm_WindoW) w), SW_HIDE);
  1220. #endif
  1221. #ifdef WIN_MOTIF
  1222.       shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1223.       if (NLM_QUIET) {
  1224.         if (Nlm_WindowHasBeenShown ((Nlm_WindoW) w)) {
  1225.           XtUnmapWidget (shl);
  1226.         }
  1227.       } else {
  1228.         XtUnmapWidget (shl);
  1229.       }
  1230. #endif
  1231.       Nlm_SetWindowDying ((Nlm_WindoW) w, TRUE);
  1232.       nxt = (Nlm_WindoW) Nlm_GetNext (w);
  1233.       Nlm_SetNext ((Nlm_GraphiC) q, (Nlm_GraphiC) nxt);
  1234.       Nlm_SetNext (w, (Nlm_GraphiC) dyingWindow);
  1235.       dyingWindow = (Nlm_WindoW) w;
  1236.     }
  1237.   }
  1238.   Nlm_Update ();
  1239. }
  1240.  
  1241. static void Nlm_HideWindow (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1242.  
  1243. {
  1244.   Nlm_WindowTool  wptr;
  1245. #ifdef WIN_MOTIF
  1246.   Nlm_ShellTool   shl;
  1247. #endif
  1248.  
  1249.   wptr = Nlm_ParentWindowPtr (w);
  1250.   Nlm_SetVisible (w, FALSE);
  1251. #ifdef WIN_MAC
  1252.   HideWindow (wptr);
  1253.   Nlm_Update ();
  1254. #endif
  1255. #ifdef WIN_MSWIN
  1256.   ShowWindow (wptr, SW_HIDE);
  1257.   Nlm_Update ();
  1258. #endif
  1259. #ifdef WIN_MOTIF
  1260.   shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1261.   if (NLM_QUIET) {
  1262.     if (Nlm_WindowHasBeenShown ((Nlm_WindoW) w)) {
  1263.       XtUnmapWidget (shl);
  1264.     }
  1265.   } else {
  1266.     XtUnmapWidget (shl);
  1267.   }
  1268.   Nlm_DoDeactivate (w, FALSE);
  1269.   Nlm_Update ();
  1270. #endif
  1271. }
  1272.  
  1273. /* Thanks to Mike Isaev for suggesting this solution to modal windows. */
  1274.  
  1275. static void Nlm_EnableOneWindow (Nlm_WindoW w, Nlm_Boolean onOffFlag)
  1276.  
  1277. {
  1278. #ifdef WIN_MSWIN
  1279.   Nlm_WindowTool  wptr;
  1280. #endif
  1281. #ifdef WIN_MOTIF
  1282.   Nlm_ShellTool   shl;
  1283. #endif
  1284.  
  1285.   if (w != NULL && w != Nlm_desktopWindow && w != Nlm_systemWindow) {
  1286. #ifdef WIN_MSWIN
  1287.     wptr = Nlm_GetWindowPtr (w);
  1288.     EnableWindow (wptr, onOffFlag);
  1289. #endif
  1290. #ifdef WIN_MOTIF
  1291.     shl = Nlm_GetWindowShell (w);
  1292.     XtVaSetValues (shl, XmNsensitive, onOffFlag, NULL);
  1293. #endif
  1294.   }
  1295. }
  1296.  
  1297. static void Nlm_EnableOtherWindows (Nlm_WindoW notThisWindow, Nlm_Boolean onOffFlag)
  1298.  
  1299. {
  1300.   Nlm_WindoW  w;
  1301.  
  1302.   w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  1303.   while (w != NULL && w != Nlm_systemWindow) {
  1304.     if (w != notThisWindow) {
  1305.       Nlm_EnableOneWindow (w, onOffFlag);
  1306.     }
  1307.     w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  1308.   }
  1309. }
  1310.  
  1311. static void Nlm_HideModal (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1312.  
  1313. {
  1314.   Nlm_HideWindow (w, setFlag, savePort);
  1315.   Nlm_EnableOtherWindows ((Nlm_WindoW ) w, TRUE);
  1316. }
  1317.  
  1318. /* static -- dgg, make this public */
  1319. void Nlm_ResizeWindow (Nlm_GraphiC w, Nlm_Int2 dragHeight,
  1320.                               Nlm_Int2 scrollWidth, Nlm_Int2 minWidth,
  1321.                               Nlm_Int2 extraHeight)
  1322.  
  1323. {
  1324.   Nlm_BoxData     bdata;
  1325.   Nlm_Int4        free;
  1326.   Nlm_Int2        height;
  1327.   Nlm_Int4        leftpix;
  1328.   Nlm_PoinT       lpt;
  1329.   Nlm_Int2        menuHeight;
  1330.   Nlm_RecT        r;
  1331.   Nlm_Int4        rleft;
  1332.   Nlm_Int4        rtop;
  1333.   Nlm_Int4        toppix;
  1334.   Nlm_Int2        width;
  1335.   Nlm_WindowTool  wptr;
  1336. #ifdef WIN_MOTIF
  1337.   Nlm_ButtoN      b;
  1338.   Nlm_MainTool    man;
  1339.   Nlm_ShellTool   shl;
  1340.   Window          xtw;
  1341. #endif
  1342.  
  1343.   if (! Nlm_WindowHasBeenShown ((Nlm_WindoW) w)) {
  1344. #ifdef WIN_MAC
  1345.     menuHeight = 21;
  1346.     TextFont (0);
  1347.     TextSize (0);
  1348. #endif
  1349. #ifdef WIN_MSWIN
  1350.     menuHeight = 0;
  1351. #endif
  1352. #ifdef WIN_MOTIF
  1353.     menuHeight = 0;
  1354. #endif
  1355.     Nlm_GetRect (w, &r);
  1356.     if (r.left < 0 || r.right < 0 || r.top < 0 || r.bottom < 0) {
  1357.       Nlm_GetBoxData ((Nlm_BoX) w, &bdata);
  1358.       lpt = bdata.limitPoint;
  1359.       if (r.right < 0) {
  1360.         width = lpt.x + scrollWidth + bdata.xMargin;
  1361.         if (width < minWidth) {
  1362.           width = minWidth;
  1363.         }
  1364.       } else {
  1365.         width = r.right;
  1366.       }
  1367.       if (r.bottom < 0) {
  1368.         height = lpt.y + scrollWidth + extraHeight + bdata.yMargin;
  1369.       } else {
  1370.         height = r.bottom + extraHeight;
  1371.       }
  1372.       if (r.left < 0) {
  1373.         free = screenBitBounds.right - width;
  1374.         rleft = (Nlm_Int4) r.left;
  1375.         leftpix = free * (-rleft) / 100;
  1376.         r.left = (Nlm_Int2) leftpix;
  1377.       }
  1378.       if (r.top < 0) {
  1379.         free = screenBitBounds.bottom - height - menuHeight - dragHeight;
  1380.         rtop = (Nlm_Int4) r.top;
  1381.         toppix = (free * (-rtop) / (Nlm_Int4) 100);
  1382.         r.top = (Nlm_Int2) (toppix + menuHeight + dragHeight);
  1383.       }
  1384.       r.right = r.left + width;
  1385.       r.bottom = r.top + height;
  1386.       Nlm_SetRect (w, &r);
  1387.       wptr = Nlm_GetWindowPtr ((Nlm_WindoW) w);
  1388. #ifdef WIN_MAC
  1389.       SizeWindow (wptr, width, height, FALSE);
  1390.       MoveWindow (wptr, r.left, r.top, FALSE);
  1391. #endif
  1392. #ifdef WIN_MSWIN
  1393.       MoveWindow (wptr, r.left, r.top, width, height, FALSE);
  1394. #endif
  1395. #ifdef WIN_MOTIF
  1396.       shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1397.       man = Nlm_GetWindowMain ((Nlm_WindoW) w);
  1398.       XtVaSetValues (shl,
  1399.                      XmNx, (Position) r.left,
  1400.                      XmNy, (Position) r.top, 
  1401.                      XmNwidth, (Dimension) width,
  1402.                      XmNheight, (Dimension) height, 
  1403.                      NULL);
  1404.       XtVaSetValues (man,
  1405.                      XmNwidth, (Dimension) width,
  1406.                      XmNheight, (Dimension) height, 
  1407.                      NULL);
  1408.       XtVaSetValues (wptr,
  1409.                      XmNwidth, (Dimension) width,
  1410.                      XmNheight, (Dimension) height, 
  1411.                      NULL);
  1412. #endif
  1413.     }
  1414. #ifdef WIN_MOTIF
  1415.     if (NLM_QUIET && (! Nlm_IsWindowDying ((Nlm_WindoW) w))) {
  1416.       b = Nlm_GetWindowDefaultButton ((Nlm_WindoW) w);
  1417.       if (b != NULL) {
  1418.         Nlm_MapDefaultButton ((Nlm_WindoW) w, b);
  1419.       }
  1420.       shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1421.       XtRealizeWidget (shl);
  1422.       man = Nlm_GetWindowMain ((Nlm_WindoW) w);
  1423.       xtw = XtWindow (man);
  1424.       if (xtw != 0) {
  1425.         XDefineCursor (Nlm_currentXDisplay, xtw, currentCursor);
  1426.       }
  1427.     }
  1428. #endif
  1429.   }
  1430. }
  1431.  
  1432. static void Nlm_ShowPlain (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1433.  
  1434. {
  1435.   Nlm_Int2        extra;
  1436.   Nlm_WindowTool  wptr;
  1437. #ifdef WIN_MOTIF
  1438.   Nlm_ShellTool   shl;
  1439. #endif
  1440.  
  1441.   wptr = Nlm_ParentWindowPtr (w);
  1442. #ifdef WIN_MAC
  1443.   Nlm_ResizeWindow (w, 0, 0, 0, 0);
  1444.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1445.   if (setFlag) {
  1446.     Nlm_SetVisible (w, TRUE);
  1447.     ShowWindow (wptr);
  1448.   }
  1449. #endif
  1450. #ifdef WIN_MSWIN
  1451.   extra = 2 * GetSystemMetrics (SM_CYBORDER);
  1452.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1453.     extra += GetSystemMetrics (SM_CYMENU);
  1454.   }
  1455.   Nlm_ResizeWindow (w, 0, 0, 0, extra);
  1456.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1457.   if (setFlag) {
  1458.     Nlm_SetVisible (w, TRUE);
  1459.     ShowWindow (wptr, SW_SHOW);
  1460.     UpdateWindow (wptr);
  1461.   }
  1462. #endif
  1463. #ifdef WIN_MOTIF
  1464.   extra = 0;
  1465.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1466.     extra += 31;
  1467.   }
  1468.   Nlm_ResizeWindow (w, 0, 0, 0, extra);
  1469.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1470.   if (setFlag) {
  1471.     Nlm_SetVisible (w, TRUE);
  1472.     shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1473.     XtMapWidget (shl);   
  1474.     Nlm_DoActivate ((Nlm_GraphiC) w, FALSE);
  1475.   }
  1476. #endif
  1477.   Nlm_Update ();
  1478. }
  1479.  
  1480. static void Nlm_ShowNormal (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1481.  
  1482. {
  1483.   Nlm_Int2        extra;
  1484.   Nlm_Char        title [256];
  1485.   Nlm_WindowTool  wptr;
  1486. #ifdef WIN_MOTIF
  1487.   Nlm_ShellTool   shl;
  1488. #endif
  1489.  
  1490.   wptr = Nlm_ParentWindowPtr (w);
  1491.   Nlm_GetWindowTitle (w, 0, title, sizeof (title));
  1492. #ifdef WIN_MAC
  1493.   Nlm_ResizeWindow (w, 20, 0, Nlm_StringWidth (title) + 70, 0);
  1494.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1495.   if (setFlag) {
  1496.     Nlm_SetVisible (w, TRUE);
  1497.     ShowWindow (wptr);
  1498.   }
  1499. #endif
  1500. #ifdef WIN_MSWIN
  1501.   extra = GetSystemMetrics (SM_CYCAPTION) + 2 * GetSystemMetrics (SM_CYFRAME);
  1502.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1503.     extra += GetSystemMetrics (SM_CYMENU);
  1504.   }
  1505.   Nlm_ResizeWindow (w, 0, 0, Nlm_StringWidth (title) + 80, extra);
  1506.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1507.   if (setFlag) {
  1508.     Nlm_SetVisible (w, TRUE);
  1509.     ShowWindow (wptr, SW_SHOW);
  1510.     UpdateWindow (wptr);
  1511.   }
  1512. #endif
  1513. #ifdef WIN_MOTIF
  1514.   extra = 0;
  1515.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1516.     extra += 31;
  1517.   }
  1518.   Nlm_ResizeWindow (w, 0, 0, Nlm_StringWidth (title) + 65, extra);
  1519.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1520.   if (setFlag) {
  1521.     Nlm_SetVisible (w, TRUE);
  1522.     shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1523.     XtMapWidget (shl);   
  1524.     Nlm_DoActivate ((Nlm_GraphiC) w, FALSE);
  1525.   }
  1526. #endif
  1527.   Nlm_Update ();
  1528. }
  1529.  
  1530. static void Nlm_ShowModal (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1531.  
  1532. {
  1533.   Nlm_ShowNormal (w, setFlag, savePort);
  1534.   Nlm_EnableOtherWindows ((Nlm_WindoW ) w, FALSE);
  1535. }
  1536.  
  1537. static void Nlm_ShowDocument (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1538.  
  1539. {
  1540.   Nlm_Int2        extra;
  1541.   Nlm_Char        title [256];
  1542.   Nlm_WindowTool  wptr;
  1543. #ifdef WIN_MOTIF
  1544.   Nlm_ShellTool   shl;
  1545. #endif
  1546.  
  1547.   wptr = Nlm_ParentWindowPtr (w);
  1548.   Nlm_GetWindowTitle (w, 0, title, sizeof (title));
  1549. #ifdef WIN_MAC
  1550.   Nlm_ResizeWindow (w, 20, 16, Nlm_StringWidth (title) + 70, 0); 
  1551.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1552.   if (setFlag) {
  1553.     Nlm_SetVisible (w, TRUE);
  1554.     ShowWindow (wptr);
  1555.   }
  1556. #endif
  1557. #ifdef WIN_MSWIN
  1558.   extra = GetSystemMetrics (SM_CYCAPTION) + 2 * GetSystemMetrics (SM_CYBORDER);
  1559.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1560.     extra += GetSystemMetrics (SM_CYMENU);
  1561.   }
  1562.   Nlm_ResizeWindow (w, 0, 0, Nlm_StringWidth (title) + 80, extra);
  1563.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1564.   if (setFlag) {
  1565.     Nlm_SetVisible (w, TRUE);
  1566.     ShowWindow (wptr, SW_SHOW);
  1567.     UpdateWindow (wptr);
  1568.   }
  1569. #endif
  1570. #ifdef WIN_MOTIF
  1571.   extra = 0;
  1572.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1573.     extra += 31;
  1574.   }
  1575.   Nlm_ResizeWindow (w, 0, 0, Nlm_StringWidth (title) + 65, extra);
  1576.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1577.   if (setFlag) {
  1578.     Nlm_SetVisible (w, TRUE);
  1579.     shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1580.     XtMapWidget (shl);   
  1581.     Nlm_DoActivate ((Nlm_GraphiC) w, FALSE);
  1582.   }
  1583. #endif
  1584.   Nlm_Update ();
  1585. }
  1586.  
  1587. extern void Nlm_RealizeWindow (Nlm_WindoW w)
  1588.  
  1589. {
  1590.   if (w != NULL) {
  1591.     Nlm_DoShow ((Nlm_GraphiC) w, FALSE, TRUE);
  1592.   }
  1593. }
  1594.  
  1595. extern Nlm_WindoW Nlm_WhichWindow (Nlm_PoinT mouseLoc)
  1596.  
  1597. {
  1598. #ifdef WIN_MAC
  1599.   Nlm_PoinT       point;
  1600.   Nlm_PointTool   ptool;
  1601.   Nlm_Int2        windowLoc;
  1602.   Nlm_WindowTool  wptr;
  1603.  
  1604.   point = mouseLoc;
  1605.   Nlm_LocalToGlobal (&point);
  1606.   Nlm_PoinTToPointTool (point, &ptool);
  1607.   windowLoc = FindWindow (ptool, &wptr);
  1608.   return Nlm_FindWindowRec (wptr);
  1609. #endif
  1610. #ifdef WIN_MSWIN
  1611.   Nlm_PoinT       point;
  1612.   Nlm_PointTool   ptool;
  1613.   Nlm_WindoW      rsult;
  1614.   Nlm_WindowTool  wptr;
  1615.  
  1616.   rsult = NULL;
  1617.   point = mouseLoc;
  1618.   Nlm_LocalToGlobal (&point);
  1619.   Nlm_PoinTToPointTool (point, &ptool);
  1620.   wptr = WindowFromPoint (ptool);
  1621.   if (wptr != NULL) {
  1622.     rsult = (Nlm_WindoW) GetProp (wptr, (LPSTR) "Nlm_VibrantProp");
  1623.   }
  1624.   return rsult;
  1625. #endif
  1626. #ifdef WIN_MOTIF
  1627.   return NULL;
  1628. #endif
  1629. }
  1630.  
  1631. extern Nlm_Boolean Nlm_InWindow (Nlm_PoinT mouseLoc)
  1632.  
  1633. {
  1634.   return (Nlm_Boolean) (Nlm_WhichWindow (mouseLoc) != Nlm_desktopWindow);
  1635. }
  1636.  
  1637. extern Nlm_WindoW Nlm_FrontWindow ()
  1638.  
  1639. {
  1640. #ifdef WIN_MAC
  1641.   return (Nlm_FindWindowRec (FrontWindow ()));
  1642. #endif
  1643. #ifdef WIN_MSWIN
  1644.   return (Nlm_FindWindowRec (Nlm_currentHWnd));
  1645. #endif
  1646. #ifdef WIN_MOTIF
  1647.   return NULL;
  1648. #endif
  1649. }
  1650.  
  1651. extern Nlm_Boolean Nlm_InFront (Nlm_WindoW w)
  1652.  
  1653. {
  1654. #ifdef WIN_MAC
  1655.   return (w == Nlm_FrontWindow ());
  1656. #endif
  1657. #ifdef WIN_MSWIN
  1658.   return FALSE;
  1659. #endif
  1660. #ifdef WIN_MOTIF
  1661.   return FALSE;
  1662. #endif
  1663. }
  1664.  
  1665. extern void Nlm_UseWindow (Nlm_WindoW w)
  1666.  
  1667. {
  1668.   Nlm_WindowTool  wptr;
  1669. #ifdef WIN_MOTIF
  1670.   Nlm_ShellTool   shl;
  1671. #endif
  1672.  
  1673.   if (w != NULL && w != Nlm_desktopWindow) {
  1674.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1675.     if (wptr != NULL && (! Nlm_IsWindowDying (w))) {
  1676. #ifdef WIN_MAC
  1677.       SetPort (wptr);
  1678.       Nlm_SetUpdateRegion (wptr);
  1679.       Nlm_ResetDrawingTools ();
  1680. #endif
  1681. #ifdef WIN_MSWIN
  1682.       Nlm_currentHDC = Nlm_GetWindowPort (w);
  1683.       Nlm_currentHWnd = wptr;
  1684. #endif
  1685. #ifdef WIN_MOTIF
  1686.       shl = Nlm_GetWindowShell (w);
  1687.       Nlm_currentXWindow = XtWindow (shl);
  1688.       Nlm_currentXGC = Nlm_GetWindowPort (w);
  1689. #endif
  1690.       Nlm_currentWindowTool = wptr;
  1691.     }
  1692.   }
  1693. }
  1694.  
  1695. extern Nlm_WindoW Nlm_CurrentWindow ()
  1696.  
  1697. {
  1698.   Nlm_WindoW  rsult;
  1699.  
  1700.   rsult = Nlm_FindWindowRec (Nlm_currentWindowTool);
  1701.   return rsult;
  1702. }
  1703.  
  1704. extern Nlm_Boolean Nlm_UsingWindow (Nlm_WindoW w)
  1705.  
  1706. {
  1707.   return (Nlm_Boolean) (w == Nlm_CurrentWindow ());
  1708. }
  1709.  
  1710. extern Nlm_WindoW Nlm_ActiveWindow ()
  1711.  
  1712. {
  1713.   Nlm_WindoW      rsult;
  1714.   Nlm_WindowTool  wptr;
  1715.  
  1716.   rsult = NULL;
  1717. #ifdef WIN_MAC
  1718.   rsult = Nlm_theWindow;
  1719. #endif
  1720. #ifdef WIN_MSWIN
  1721.   wptr = GetActiveWindow ();
  1722.   if (wptr != NULL) {
  1723.     rsult = (Nlm_WindoW) GetProp (wptr, (LPSTR) "Nlm_VibrantProp");
  1724.   }
  1725. #endif
  1726. #ifdef WIN_MOTIF
  1727. #endif
  1728.   return rsult;
  1729. }
  1730.  
  1731. #ifdef WIN_MAC
  1732. static Nlm_WindoW Nlm_PrevVisWindow (Nlm_WindoW w)
  1733.  
  1734. {
  1735.   WindowPeek  p;
  1736.   WindowPeek  q;
  1737.   WindowPeek  t;
  1738.  
  1739.   if (frontWindow == Nlm_desktopWindow) {
  1740.     return Nlm_desktopWindow;
  1741.   } else if (frontWindow == w) {
  1742.     return frontWindow;
  1743.   } else {
  1744.     p = (WindowPeek) Nlm_ParentWindowPtr ((Nlm_GraphiC) frontWindow);
  1745.     q = p;
  1746.     t = (WindowPeek) Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1747.     while (p != NULL) {
  1748.       if (p == t) {
  1749.         p = NULL;
  1750.       } else if (p->visible != 0) {
  1751.         q = p;
  1752.         p = p->nextWindow;
  1753.       } else {
  1754.         p = p->nextWindow;
  1755.       }
  1756.     }
  1757.     return (Nlm_FindWindowRec ((Nlm_WindowTool) q));
  1758.   }
  1759. }
  1760. #endif
  1761.  
  1762. static void Nlm_SelectWindow (Nlm_GraphiC w, Nlm_Boolean savePort)
  1763.  
  1764. {
  1765.   Nlm_WindowTool  wptr;
  1766. #ifdef WIN_MOTIF
  1767.   Nlm_ShellTool   shl;
  1768. #endif
  1769.  
  1770.   if (w != NULL && (Nlm_WindoW) w != Nlm_desktopWindow) {
  1771.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1772.     if (wptr != NULL && (! Nlm_IsWindowDying ((Nlm_WindoW) w))) {
  1773. #ifdef WIN_MAC
  1774.       SelectWindow (wptr);
  1775.       SetPort (wptr);
  1776.       Nlm_SetUpdateRegion (wptr);
  1777.       Nlm_ResetDrawingTools ();
  1778. #endif
  1779. #ifdef WIN_MSWIN
  1780.       BringWindowToTop (wptr);
  1781. #ifndef DCLAP
  1782. /* M.I */
  1783.       if( IsIconic( wptr ) )
  1784.         ShowWindow( wptr, SW_RESTORE );  /* de-Iconize window */
  1785. /* M.I */
  1786. #endif
  1787.       Nlm_currentHDC = Nlm_GetWindowPort ((Nlm_WindoW) w);
  1788.       Nlm_currentHWnd = wptr;
  1789. #endif
  1790. #ifdef WIN_MOTIF
  1791.       if (Nlm_WindowHasBeenShown ((Nlm_WindoW) w)) {
  1792.         if (Nlm_currentXDisplay != NULL) {
  1793.           shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1794.           XMapRaised (Nlm_currentXDisplay, XtWindow (shl));
  1795.         }
  1796.       }
  1797. #endif
  1798.       Nlm_currentWindowTool = wptr;
  1799.       Nlm_Update ();
  1800.     }
  1801.   }
  1802. }
  1803.  
  1804. extern void Nlm_EraseWindow (Nlm_WindoW w)
  1805.  
  1806. {
  1807. #ifdef WIN_MAC
  1808.   Nlm_RecT        r;
  1809.   Nlm_PortTool    temp;
  1810.   Nlm_WindowTool  wptr;
  1811.  
  1812.   if (w != NULL) {
  1813.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1814.     GetPort (&temp);
  1815.     SetPort (wptr);
  1816.     Nlm_ResetDrawingTools ();
  1817.     Nlm_currentWindowTool = wptr;
  1818.     Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1819.     Nlm_EraseRect (&r);
  1820.     SetPort (temp);
  1821.     Nlm_currentWindowTool = temp;
  1822.     Nlm_Update ();
  1823.   }
  1824. #endif
  1825. #ifdef WIN_MSWIN
  1826. #endif
  1827. #ifdef WIN_MOTIF
  1828. #endif
  1829. }
  1830.  
  1831. #ifdef WIN_MAC
  1832. static Nlm_Boolean Nlm_DragClick (Nlm_GraphiC w, Nlm_PoinT pt)
  1833.  
  1834. {
  1835.   Nlm_PointTool   ptool;
  1836.   Nlm_RecT        r;
  1837.   Nlm_RectTool    rtool;
  1838.   Nlm_Boolean     rsult;
  1839.   Nlm_Int2        windowLoc;
  1840.   Nlm_WindowData  wdata;
  1841.   Nlm_WindowTool  wptr;
  1842.  
  1843.   rsult = FALSE;
  1844.   Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  1845.   windowLoc = FindWindow (ptool, &wptr);
  1846.   if (windowLoc == inDrag) {
  1847.     Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  1848.     Nlm_RecTToRectTool (&(wdata.dragArea), &rtool);
  1849.     DragWindow (wptr, ptool, &rtool);
  1850.     Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1851.     Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.left));
  1852.     Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.right));
  1853.     Nlm_SetRect (w, &r);
  1854.     rsult = TRUE;
  1855.   }
  1856.   return rsult;
  1857. }
  1858.  
  1859. static void Nlm_UpdateScrollBar (Nlm_GraphiC w)
  1860.  
  1861. {
  1862.   Nlm_RecT        barArea;
  1863.   Nlm_WindowTool  wptr;
  1864.  
  1865.   wptr = Nlm_ParentWindowPtr (w);
  1866.   Nlm_RectToolToRecT (&(wptr->portRect), &barArea);
  1867.   barArea.left = barArea.right - 16;
  1868.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1869.     barArea.top = barArea.top + 21;
  1870.   }
  1871.   Nlm_InvalRect (&barArea);
  1872.   Nlm_RectToolToRecT (&(wptr->portRect), &barArea);
  1873.   barArea.top = barArea.bottom - 16;
  1874.   Nlm_InvalRect (&barArea);
  1875. }
  1876.  
  1877. static Nlm_Boolean Nlm_GrowClick (Nlm_GraphiC w, Nlm_PoinT pt)
  1878.  
  1879. {
  1880.   Nlm_Int2         ht;
  1881.   Nlm_Int4         newSize;
  1882.   Nlm_PointTool    ptool;
  1883.   Nlm_RecT         r;
  1884.   Nlm_WndActnProc  resize;
  1885.   Nlm_RectTool     rtool;
  1886.   Nlm_Boolean      rsult;
  1887.   Nlm_Int2         wd;
  1888.   Nlm_WindowData   wdata;
  1889.   Nlm_Int2         windowLoc;
  1890.   Nlm_WindowTool   wptr;
  1891.  
  1892.   rsult = FALSE;
  1893.   Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  1894.   windowLoc = FindWindow (ptool, &wptr);
  1895.   if (windowLoc == inGrow) {
  1896.     Nlm_LoadRect (&r, -32768, -32768, 32767, 32767);
  1897.     Nlm_RecTToRectTool (&r, &rtool);
  1898.     ClipRect (&rtool);
  1899.     Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  1900.     Nlm_RecTToRectTool (&(wdata.growArea), &rtool);
  1901.     newSize = GrowWindow (wptr, ptool, &rtool);
  1902.     wd = LoWord (newSize);
  1903.     ht = HiWord (newSize);
  1904.  /* dgg -- bug fix: simple click on grow box caused it to resize to 0 -- 
  1905.     should check here for 0 == no change.  Also make minsize bigger. 
  1906.  */
  1907.     if (! newSize) {
  1908.       ClipRect (&(wptr->portRect));
  1909.       return rsult;
  1910.     }
  1911.     if (wd < 50) {
  1912.       wd = 50;
  1913.     }
  1914.     if (ht < 32) {
  1915.       ht = 32;
  1916.     }
  1917.     Nlm_UpdateScrollBar (w);
  1918.     SizeWindow (wptr, wd, ht, TRUE);
  1919.     Nlm_UpdateScrollBar (w);
  1920.     wptr = Nlm_GetWindowPtr ((Nlm_WindoW) w);
  1921.     Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1922.     ClipRect (&(wptr->portRect));
  1923.     Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.left));
  1924.     Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.right));
  1925.     Nlm_SetRect (w, &r);
  1926.     resize = wdata.resize;
  1927.     if (resize != NULL) {
  1928.       resize ((Nlm_WindoW) w);
  1929.     }
  1930.     rsult = TRUE;
  1931.   }
  1932.   return rsult;
  1933. }
  1934.  
  1935. static void Nlm_DrawGrowIcon (Nlm_GraphiC w)
  1936.  
  1937. {
  1938.   Nlm_RecT        r;
  1939.   Nlm_RectTool    rtool;
  1940.   PenState        state;
  1941.   Nlm_PortTool    temp;
  1942.   Nlm_WindowTool  wptr;
  1943.  
  1944.   GetPort (&temp);
  1945.   GetPenState (&state);
  1946.   wptr = Nlm_ParentWindowPtr (w);
  1947.   Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1948.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1949.     Nlm_RecTToRectTool (&r, &rtool);
  1950.     ClipRect (&rtool);
  1951.     MoveTo (r.right - 16, 20);
  1952.     LineTo (r.right, 20);
  1953.     r.top = r.top + 21;
  1954.   }
  1955. #ifdef DCLAP
  1956.     /* clip out the scrollbar guides */
  1957.   r.left = r.right - 15;
  1958.   r.top = r.bottom - 15;
  1959. #endif
  1960.   Nlm_RecTToRectTool (&r, &rtool);
  1961.   ClipRect (&rtool);
  1962.   DrawGrowIcon (wptr);
  1963.   r.top = wptr->portRect.top;
  1964. #ifdef DCLAP
  1965.   /* dgg- this cliprect is the culprit for preventing scrollbar updates by subviews */
  1966.   /* try clipping a region that excludes just the growicon?? */
  1967.   r.left = wptr->portRect.left;
  1968. #else
  1969.   r.right = r.right - 16;
  1970.   r.bottom = r.bottom - 16;
  1971. #endif
  1972.   Nlm_RecTToRectTool (&r, &rtool);
  1973.   ClipRect (&rtool);
  1974.   SetPort (temp);
  1975.   Nlm_currentWindowTool = temp;
  1976.   Nlm_SetUpdateRegion (temp);
  1977.   SetPenState (&state);
  1978. }
  1979.  
  1980. static Nlm_Boolean Nlm_ZoomClick (Nlm_GraphiC w, Nlm_PoinT pt)
  1981.  
  1982. {
  1983.   Nlm_PointTool    ptool;
  1984.   Nlm_RecT         r;
  1985.   Nlm_WndActnProc  resize;
  1986.   Nlm_Boolean      rsult;
  1987.   Nlm_RectTool     rtool;
  1988.   Nlm_WindowData   wdata;
  1989.   Nlm_Int2         windowLoc;
  1990.   WindowPeek       wpeek;
  1991.   Nlm_WindowTool   wptr;
  1992.   WStateData       **wshdl;
  1993.   WStateData       *wsptr;
  1994.  
  1995.   rsult = FALSE;
  1996.   Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  1997.   windowLoc = FindWindow (ptool, &wptr);
  1998.   if (windowLoc == inZoomIn || windowLoc == inZoomOut) {
  1999.     if (TrackBox (wptr, ptool, windowLoc)) {
  2000.       wpeek = (WindowPeek) wptr;
  2001.       wshdl = (WStateData**) wpeek->dataHandle;
  2002.       wsptr = *wshdl;
  2003.       Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2004.       r = wdata.zoomArea;
  2005.       Nlm_RecTToRectTool (&r, &(wsptr->stdState));
  2006.       Nlm_RectToolToRecT (&(wptr->portRect), &r);
  2007.       ClipRect (&(wptr->portRect));
  2008.       Nlm_EraseRect (&r);
  2009.       ZoomWindow (wptr, windowLoc, FALSE);
  2010.       Nlm_UpdateScrollBar (w);
  2011.       wptr = Nlm_GetWindowPtr ((Nlm_WindoW) w);
  2012.       Nlm_RectToolToRecT (&(wptr->portRect), &r);
  2013.       ClipRect (&(wptr->portRect));
  2014.       Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.left));
  2015.       Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.right));
  2016.       Nlm_SetRect (w, &r);
  2017.       resize = wdata.resize;
  2018.       if (resize != NULL) {
  2019.         resize ((Nlm_WindoW) w);
  2020.       }
  2021.     }
  2022.     rsult = TRUE;
  2023.   }
  2024.   return rsult;
  2025. }
  2026.  
  2027. static Nlm_Boolean Nlm_CloseClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2028.  
  2029. {
  2030.   Nlm_WndActnProc  cls;
  2031.   Nlm_PointTool    ptool;
  2032.   Nlm_Boolean      rsult;
  2033.   Nlm_WindowData   wdata;
  2034.   Nlm_Int2         windowLoc;
  2035.   Nlm_WindowTool   wptr;
  2036.  
  2037.   rsult = FALSE;
  2038.   Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  2039.   windowLoc = FindWindow (ptool, &wptr);
  2040.   if (windowLoc == inGoAway) {
  2041.     if (TrackGoAway (wptr, ptool)) {
  2042.       Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2043.       cls = wdata.close;
  2044.       if (cls != NULL) {
  2045.         cls ((Nlm_WindoW) w);
  2046.       }
  2047.     }
  2048.     rsult = TRUE;
  2049.   }
  2050.   return rsult;
  2051. }
  2052.  
  2053. typedef struct revItem {
  2054.   Nlm_GraphiC          graphic;
  2055.   struct revItem  PNTR next;
  2056. } Nlm_RevItem, PNTR Nlm_RevPtr;
  2057.  
  2058. static Nlm_Boolean Nlm_ContentClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2059.  
  2060. {
  2061.   Nlm_GraphiC    g;
  2062.   Nlm_MenuBaR    mb;
  2063.   Nlm_GraphiC    n;
  2064.   Nlm_RevPtr     next;
  2065.   Nlm_Boolean    notInside;
  2066.   Nlm_PointTool  ptool;
  2067.   Nlm_RevPtr     thisitem;
  2068.   Nlm_RevPtr     top;
  2069.  
  2070.   Nlm_localMouse = Nlm_globalMouse;
  2071.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2072.   g = Nlm_GetChild (w);
  2073.   notInside = TRUE;
  2074.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2075.   if (mb != NULL) {
  2076.     if (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2077.         Nlm_DoClick ((Nlm_GraphiC) mb, Nlm_localMouse)) {
  2078.       notInside = FALSE;
  2079.     }
  2080.   }
  2081.   /*
  2082.   while (g != NULL && notInside) {
  2083.     n = Nlm_GetNext (g);
  2084.     if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoClick (g, Nlm_localMouse)) {
  2085.       notInside = FALSE;
  2086.     }
  2087.     g = n;
  2088.   }
  2089.   */
  2090.   if (g != NULL && notInside) {
  2091.     top = NULL;
  2092.     while (g != NULL) {
  2093.       thisitem = (Nlm_RevPtr) Nlm_MemNew (sizeof (Nlm_RevItem));
  2094.       if (thisitem != NULL) {
  2095.         thisitem->graphic = g;
  2096.         thisitem->next = top;
  2097.         top = thisitem;
  2098.       }
  2099.       g = Nlm_GetNext (g);
  2100.     }
  2101.     thisitem = top;
  2102.     while (thisitem != NULL && notInside) {
  2103.       next = thisitem->next;
  2104.       g = thisitem->graphic;
  2105.       if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoClick (g, Nlm_localMouse)) {
  2106.         notInside = FALSE;
  2107.       }
  2108.       thisitem = next;
  2109.     }
  2110.     thisitem = top;
  2111.     while (thisitem != NULL) {
  2112.       next = thisitem->next;
  2113.       Nlm_MemFree (thisitem);
  2114.       thisitem = next;
  2115.     }
  2116.   }
  2117.    if (notInside) {
  2118.     GetMouse (&ptool);
  2119.     Nlm_PointToolToPoinT (ptool, &Nlm_localMouse);
  2120.     if ((Nlm_WindoW) w != Nlm_WhichWindow (Nlm_localMouse)) {
  2121.       notInside = FALSE;
  2122.     }
  2123.   }
  2124.   return (! notInside);
  2125. }
  2126.  
  2127. static Nlm_Boolean Nlm_CommonClick (Nlm_GraphiC w, Nlm_PoinT pt,
  2128.                                     Nlm_Boolean close, Nlm_Boolean drag,
  2129.                                     Nlm_Boolean grow, Nlm_Boolean zoom)
  2130.  
  2131. {
  2132.   Nlm_Boolean     rsult;
  2133.   PenState        state;
  2134.   Nlm_PortTool    temp;
  2135.   Nlm_WindowTool  wptr;
  2136.  
  2137.   rsult = FALSE;
  2138.   if (chosenWindow == (Nlm_WindoW) w) {
  2139.     wptr = Nlm_ParentWindowPtr (w);
  2140.     GetPort (&temp);
  2141.     GetPenState (&state);
  2142.     SetPort (wptr);
  2143.     Nlm_currentWindowTool = wptr;
  2144.     Nlm_SetUpdateRegion (wptr);
  2145.     Nlm_ResetDrawingTools ();
  2146.     if ((close && Nlm_CloseClick (w, pt)) ||
  2147.        (drag && Nlm_DragClick (w, pt)) ||
  2148.        (grow && Nlm_GrowClick (w, pt)) ||
  2149.        (zoom && Nlm_ZoomClick (w, pt))) {
  2150.     } else {
  2151.       rsult = Nlm_ContentClick (w, pt);
  2152.     }
  2153.     SetPort (temp);
  2154.     Nlm_currentWindowTool = temp;
  2155.     Nlm_SetUpdateRegion (temp);
  2156.     SetPenState (&state);
  2157.   } else if (chosenWindow != NULL) {
  2158.     Nlm_DoSelect ((Nlm_GraphiC) chosenWindow, TRUE);
  2159.   }
  2160.   return rsult;
  2161. }
  2162.  
  2163. static Nlm_Boolean Nlm_DocumentClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2164.  
  2165. {
  2166.   return Nlm_CommonClick (w, pt, TRUE, TRUE, TRUE, TRUE);
  2167. }
  2168.  
  2169. static Nlm_Boolean Nlm_DialogClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2170.  
  2171. {
  2172.   return Nlm_CommonClick (w, pt, TRUE, TRUE, FALSE, FALSE);
  2173. }
  2174.  
  2175. static Nlm_Boolean Nlm_FrozenClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2176.  
  2177. {
  2178.   return Nlm_CommonClick (w, pt, TRUE, FALSE, FALSE, FALSE);
  2179. }
  2180.  
  2181. static Nlm_Boolean Nlm_PlainClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2182.  
  2183. {
  2184.   return Nlm_CommonClick (w, pt, FALSE, FALSE, FALSE, FALSE);
  2185. }
  2186.  
  2187. static Nlm_Boolean Nlm_ModalClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2188.  
  2189. {
  2190.   Nlm_WndActnProc  cls;
  2191.   Nlm_Boolean      rsult;
  2192.   PenState         state;
  2193.   Nlm_PortTool     temp;
  2194.   Nlm_WindowData   wdata;
  2195.   Nlm_WindowTool   wptr;
  2196.  
  2197.   rsult = FALSE;
  2198.   if (chosenWindow == (Nlm_WindoW) w) {
  2199.     rsult = Nlm_CommonClick (w, pt, FALSE, FALSE, FALSE, FALSE);
  2200.     if (! rsult) {
  2201.       Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2202.       cls = wdata.close;
  2203.       if (cls != NULL) {
  2204.         wptr = Nlm_ParentWindowPtr (w);
  2205.         GetPort (&temp);
  2206.         GetPenState (&state);
  2207.         SetPort (wptr);
  2208.         Nlm_currentWindowTool = wptr;
  2209.         Nlm_SetUpdateRegion (wptr);
  2210.         Nlm_ResetDrawingTools ();
  2211.         cls ((Nlm_WindoW) w);
  2212.         SetPort (temp);
  2213.         Nlm_currentWindowTool = temp;
  2214.         Nlm_SetUpdateRegion (temp);
  2215.         SetPenState (&state);
  2216.       }
  2217.     }
  2218.   } else {
  2219.     Nlm_Beep ();
  2220.   }
  2221.   return rsult;
  2222. }
  2223.  
  2224. static Nlm_Boolean Nlm_FloatingClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2225.  
  2226. {
  2227.   Nlm_WindoW  nw;
  2228.  
  2229.   if (chosenWindow == (Nlm_WindoW) w) {
  2230.     Nlm_CommonClick (w, Nlm_globalMouse, TRUE, TRUE, FALSE, FALSE);
  2231.   } else {
  2232.     nw = Nlm_NextVisWindow ((Nlm_WindoW) w);
  2233.     Nlm_DoClick ((Nlm_GraphiC) nw, Nlm_globalMouse);
  2234.   }
  2235.   return TRUE;
  2236. }
  2237.  
  2238. static Nlm_Boolean Nlm_SystemClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2239.  
  2240. {
  2241.   Nlm_WindowTool  wptr;
  2242.  
  2243.   if (chosenWindow == (Nlm_WindoW) w) {
  2244.     wptr = Nlm_ParentWindowPtr (w);
  2245.     SystemClick (&Nlm_currentEvent, wptr);
  2246.   } else {
  2247.     Nlm_DoSelect ((Nlm_GraphiC) chosenWindow, TRUE);
  2248.   }
  2249.   return TRUE;
  2250. }
  2251.  
  2252. static Nlm_Boolean Nlm_DesktopClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2253.  
  2254. {
  2255.   Nlm_MenuBaR  mb;
  2256.  
  2257.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2258.   Nlm_localMouse = Nlm_globalMouse;
  2259.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2260.   (void) (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2261.           Nlm_DoClick ((Nlm_GraphiC) mb, Nlm_localMouse));
  2262.   return TRUE;
  2263. }
  2264. #endif
  2265.  
  2266. static void Nlm_NormalSelect (Nlm_GraphiC w, Nlm_Boolean savePort)
  2267.  
  2268. {
  2269. #ifdef WIN_MAC
  2270.   if ((! Nlm_DragClick (w, Nlm_localMouse)) || (! Nlm_cmmdKey)) {
  2271.     Nlm_SelectWindow (w, FALSE);
  2272.   }
  2273. #endif
  2274. #ifdef WIN_MSWIN
  2275.   Nlm_SelectWindow (w, FALSE);
  2276. #endif
  2277. #ifdef WIN_MOTIF
  2278.   Nlm_SelectWindow (w, FALSE);
  2279. #endif
  2280. }
  2281.  
  2282. static void Nlm_PlainSelect (Nlm_GraphiC w, Nlm_Boolean savePort)
  2283.  
  2284. {
  2285. #ifdef WIN_MAC
  2286.   Nlm_SelectWindow (w, FALSE);
  2287. #endif
  2288. #ifdef WIN_MSWIN
  2289.   Nlm_SelectWindow (w, FALSE);
  2290. #endif
  2291. #ifdef WIN_MOTIF
  2292.   Nlm_SelectWindow (w, FALSE);
  2293. #endif
  2294. }
  2295.  
  2296. static void Nlm_FloatingSelect (Nlm_GraphiC w, Nlm_Boolean savePort)
  2297.  
  2298. {
  2299. #ifdef WIN_MAC
  2300.   PenState        state;
  2301.   Nlm_PortTool    temp;
  2302.   Nlm_WindowTool  wptr;
  2303.  
  2304.   wptr = Nlm_ParentWindowPtr (w);
  2305.   GetPort (&temp);
  2306.   GetPenState (&state);
  2307.   SetPort (wptr);
  2308.   Nlm_currentWindowTool = wptr;
  2309.   Nlm_SetUpdateRegion (wptr);
  2310.   Nlm_ResetDrawingTools ();
  2311.   Nlm_localMouse = Nlm_globalMouse;
  2312.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2313.   if (Nlm_DragClick (w, Nlm_globalMouse) || Nlm_CloseClick (w, Nlm_globalMouse)) {
  2314.   } else {
  2315.     Nlm_ContentClick (w, Nlm_globalMouse);
  2316.   }
  2317.   SetPort (temp);
  2318.   Nlm_currentWindowTool = temp;
  2319.   Nlm_SetUpdateRegion (temp);
  2320.   SetPenState (&state);
  2321.   Nlm_localMouse = Nlm_globalMouse;
  2322.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2323. #endif
  2324. #ifdef WIN_MSWIN
  2325.   Nlm_SelectWindow (w, FALSE);
  2326. #endif
  2327. #ifdef WIN_MOTIF
  2328.   Nlm_SelectWindow (w, FALSE);
  2329. #endif
  2330. }
  2331.  
  2332. static void Nlm_DesktopSelect (Nlm_GraphiC w, Nlm_Boolean savePort)
  2333.  
  2334. {
  2335. #ifdef WIN_MAC
  2336.   PenState      state;
  2337.   Nlm_PortTool  temp;
  2338.  
  2339.   GetPort (&temp);
  2340.   GetPenState (&state);
  2341.   PenNormal ();
  2342.   Nlm_DesktopClick (w, Nlm_globalMouse);
  2343.   SetPort (temp);
  2344.   Nlm_currentWindowTool = temp;
  2345.   Nlm_SetUpdateRegion (temp);
  2346.   SetPenState (&state);
  2347. #endif
  2348. }
  2349.  
  2350. #ifdef WIN_MAC
  2351. static Nlm_Boolean Nlm_DesktopKey (Nlm_GraphiC w, Nlm_Char ch)
  2352.  
  2353. {
  2354.   Nlm_MenuBaR  mb;
  2355.  
  2356.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2357.   Nlm_localMouse = Nlm_globalMouse;
  2358.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2359.   if (Nlm_currentKey != '\0') {
  2360.     (void) (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2361.             Nlm_DoKey ((Nlm_GraphiC) mb, ch));
  2362.   }
  2363.   return TRUE;
  2364. }
  2365.  
  2366. static Nlm_Boolean Nlm_NormalKey (Nlm_GraphiC w, Nlm_Char ch)
  2367.  
  2368. {
  2369.   Nlm_GraphiC     g;
  2370.   Nlm_MenuBaR     mb;
  2371.   Nlm_GraphiC     n;
  2372.   Nlm_Boolean     notInside;
  2373.   PenState        state;
  2374.   Nlm_PortTool    temp;
  2375.   Nlm_WindowTool  wptr;
  2376.  
  2377.   wptr = Nlm_ParentWindowPtr (w);
  2378.   GetPort (&temp);
  2379.   GetPenState (&state);
  2380.   SetPort (wptr);
  2381.   Nlm_currentWindowTool = wptr;
  2382.   Nlm_SetUpdateRegion (wptr);
  2383.   Nlm_ResetDrawingTools ();
  2384.   Nlm_localMouse = Nlm_globalMouse;
  2385.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2386.   if (Nlm_currentKey != '\0') {
  2387.     g = Nlm_GetChild (w);
  2388.     notInside = TRUE;
  2389.     mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2390.     if (mb != NULL) {
  2391.       if (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2392.           Nlm_DoKey ((Nlm_GraphiC) mb, ch)) {
  2393.         notInside = FALSE;
  2394.       }
  2395.     }
  2396.     while (g != NULL && notInside) {
  2397.       n = Nlm_GetNext (g);
  2398.       if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoKey (g, ch)) {
  2399.         notInside = FALSE;
  2400.       }
  2401.       g = n;
  2402.     }
  2403.     if (notInside && Nlm_cmmdKey) {
  2404.       Nlm_DesktopKey ((Nlm_GraphiC) Nlm_desktopWindow, ch);
  2405.     }
  2406.   }
  2407.   SetPort (temp);
  2408.   Nlm_currentWindowTool = temp;
  2409.   Nlm_SetUpdateRegion (temp);
  2410.   SetPenState (&state);
  2411.   return TRUE;
  2412. }
  2413.  
  2414. static Nlm_Boolean Nlm_FloatingKey (Nlm_GraphiC w, Nlm_Char ch)
  2415.  
  2416. {
  2417.   Nlm_GraphiC     g;
  2418.   Nlm_MenuBaR     mb;
  2419.   Nlm_GraphiC     n;
  2420.   Nlm_WindoW      nw;
  2421.   Nlm_Boolean     notInside;
  2422.   PenState        state;
  2423.   Nlm_PortTool    temp;
  2424.   Nlm_WindowTool  wptr;
  2425.  
  2426.   wptr = Nlm_ParentWindowPtr (w);
  2427.   GetPort (&temp);
  2428.   GetPenState (&state);
  2429.   SetPort (wptr);
  2430.   Nlm_currentWindowTool = wptr;
  2431.   Nlm_SetUpdateRegion (wptr);
  2432.   Nlm_ResetDrawingTools ();
  2433.   Nlm_localMouse = Nlm_globalMouse;
  2434.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2435.   if (Nlm_currentKey != '\0') {
  2436.     g = Nlm_GetChild (w);
  2437.     notInside = TRUE;
  2438.     mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2439.     if (mb != NULL) {
  2440.       if (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2441.           Nlm_DoKey ((Nlm_GraphiC) mb, ch)) {
  2442.         notInside = FALSE;
  2443.       }
  2444.     }
  2445.     while (g != NULL && notInside) {
  2446.       n = Nlm_GetNext (g);
  2447.       if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoKey (g, ch)) {
  2448.         notInside = FALSE;
  2449.       }
  2450.       g = n;
  2451.     }
  2452.     if (notInside) {
  2453.       nw = Nlm_NextVisWindow ((Nlm_WindoW) w);
  2454.       Nlm_DoKey ((Nlm_GraphiC) nw, ch);
  2455.     }
  2456.   }
  2457.   SetPort (temp);
  2458.   Nlm_currentWindowTool = temp;
  2459.   Nlm_SetUpdateRegion (temp);
  2460.   SetPenState (&state);
  2461.   return TRUE;
  2462. }
  2463.  
  2464. static Nlm_Boolean Nlm_ModalKey (Nlm_GraphiC w, Nlm_Char ch)
  2465.  
  2466. {
  2467.   if (Nlm_cmmdKey) {
  2468.     Nlm_Beep ();
  2469.   } else {
  2470.     Nlm_NormalKey (w, ch);
  2471.   }
  2472.   return TRUE;
  2473. }
  2474.  
  2475. static void Nlm_DrawWindow (Nlm_GraphiC w, Nlm_Boolean drawGrowIcon)
  2476.  
  2477. {
  2478.   Nlm_GraphiC     g;
  2479.   Nlm_MenuBaR     mb;
  2480.   Nlm_GraphiC     n;
  2481.   Nlm_RecT        r;
  2482.   PenState        state;
  2483.   Nlm_PortTool    temp;
  2484.   Nlm_WindowTool  wptr;
  2485.  
  2486.   wptr = Nlm_ParentWindowPtr (w);
  2487.   GetPort (&temp);
  2488.   GetPenState (&state);
  2489.   SetPort (wptr);
  2490.   Nlm_currentWindowTool = wptr;
  2491.  
  2492.   Nlm_ResetDrawingTools ();
  2493.   Nlm_ResetClip ();
  2494.   PenNormal ();
  2495.  
  2496.   BeginUpdate (wptr);
  2497.   Nlm_SetUpdateRegion (wptr);
  2498.   Nlm_RectToolToRecT (&(wptr->portRect), &r);
  2499.   Nlm_EraseRect (&r);
  2500.   if (drawGrowIcon) {
  2501.     Nlm_DrawGrowIcon (w);
  2502.   }
  2503.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2504.   if (mb != NULL) {
  2505.     Nlm_DoDraw ((Nlm_GraphiC) mb);
  2506.   }
  2507.   g = Nlm_GetChild (w);
  2508.   while (g != NULL) {
  2509.     n = Nlm_GetNext (g);
  2510.     Nlm_DoDraw (g);
  2511.     g = n;
  2512.   }
  2513.   EndUpdate (wptr);
  2514.   Nlm_ResetDrawingTools ();
  2515.   Nlm_ResetClip ();
  2516.   SetPort (temp);
  2517.   Nlm_currentWindowTool = temp;
  2518.   Nlm_SetUpdateRegion (temp);
  2519.   SetPenState (&state);
  2520. }
  2521.  
  2522. static void Nlm_DocumentDraw (Nlm_GraphiC w)
  2523.  
  2524. {
  2525.   Nlm_DrawWindow (w, TRUE);
  2526. }
  2527.  
  2528. static void Nlm_NormalDraw (Nlm_GraphiC w)
  2529.  
  2530. {
  2531.   Nlm_DrawWindow (w, FALSE);
  2532. }
  2533. #endif
  2534.  
  2535. static void Nlm_ActivateWindow (Nlm_GraphiC w, Nlm_Boolean drawGrow)
  2536.  
  2537. {
  2538.   Nlm_WndActnProc  act;
  2539.   Nlm_GraphiC      g;
  2540.   Nlm_MenuBaR      mb;
  2541.   Nlm_GraphiC      n;
  2542.   Nlm_WindowData   wdata;
  2543.  
  2544.   Nlm_UseWindow ((Nlm_WindoW) w);
  2545. #ifdef WIN_MAC
  2546.   if (drawGrow) {
  2547.     Nlm_DrawGrowIcon (w);
  2548.   }
  2549. #endif
  2550.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2551.   if (mb != NULL) {
  2552.     Nlm_DoActivate ((Nlm_GraphiC) mb, FALSE);
  2553.   }
  2554.   g = Nlm_GetChild (w);
  2555.   while (g != NULL) {
  2556.     n = Nlm_GetNext (g);
  2557.     Nlm_DoActivate (g, FALSE);
  2558.     g = n;
  2559.   }
  2560.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2561.   act = wdata.activate;
  2562.   if (act != NULL) {
  2563.     act ((Nlm_WindoW) w);
  2564.   }
  2565. }
  2566.  
  2567. static void Nlm_DocumentActivate (Nlm_GraphiC w, Nlm_Boolean savePort)
  2568.  
  2569. {
  2570.   Nlm_ActivateWindow (w, TRUE);
  2571. }
  2572.  
  2573. static void Nlm_NormalActivate (Nlm_GraphiC w, Nlm_Boolean savePort)
  2574.  
  2575. {
  2576.   Nlm_ActivateWindow (w, FALSE);
  2577. }
  2578.  
  2579. static void Nlm_DeactivateWindow (Nlm_GraphiC w, Nlm_Boolean drawGrow)
  2580.  
  2581. {
  2582.   Nlm_WndActnProc  deact;
  2583.   Nlm_GraphiC      g;
  2584.   Nlm_MenuBaR      mb;
  2585.   Nlm_GraphiC      n;
  2586.   Nlm_WindowData   wdata;
  2587.  
  2588.   Nlm_UseWindow ((Nlm_WindoW) w);
  2589. #ifdef WIN_MAC
  2590.   if (drawGrow) {
  2591.     Nlm_DrawGrowIcon (w);
  2592.   }
  2593. #endif
  2594.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2595.   if (mb != NULL) {
  2596.     Nlm_DoDeactivate ((Nlm_GraphiC) mb, FALSE);
  2597.   }
  2598.   g = Nlm_GetChild (w);
  2599.   while (g != NULL) {
  2600.     n = Nlm_GetNext (g);
  2601.     Nlm_DoDeactivate (g, FALSE);
  2602.     g = n;
  2603.   }
  2604.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2605.   deact = wdata.deactivate;
  2606.   if (deact != NULL) {
  2607.     deact ((Nlm_WindoW) w);
  2608.   }
  2609. }
  2610.  
  2611. static void Nlm_DocumentDeactivate (Nlm_GraphiC w, Nlm_Boolean savePort)
  2612.  
  2613. {
  2614.   Nlm_DeactivateWindow (w, TRUE);
  2615. }
  2616.  
  2617. static void Nlm_NormalDeactivate (Nlm_GraphiC w, Nlm_Boolean savePort)
  2618.  
  2619. {
  2620.   Nlm_DeactivateWindow (w, FALSE);
  2621. }
  2622.  
  2623. #ifdef WIN_MAC
  2624. static Nlm_Boolean Nlm_NormalIdle (Nlm_GraphiC w, Nlm_PoinT pt)
  2625.  
  2626. {
  2627.   Nlm_GraphiC  g;
  2628.   Nlm_GraphiC  n;
  2629.  
  2630.   g = Nlm_GetChild (w);
  2631.   while (g != NULL) {
  2632.     n = Nlm_GetNext (g);
  2633.     Nlm_DoIdle (g, Nlm_localMouse);
  2634.     g = n;
  2635.   }
  2636.   return TRUE;
  2637. }
  2638.  
  2639. static Nlm_Boolean Nlm_FloatingIdle (Nlm_GraphiC w, Nlm_PoinT pt)
  2640.  
  2641. {
  2642.   Nlm_WindoW   nw;
  2643.  
  2644.   nw = Nlm_NextVisWindow ((Nlm_WindoW) w);
  2645.   Nlm_DoIdle ((Nlm_GraphiC) nw, pt);
  2646.   return TRUE;
  2647. }
  2648. #endif
  2649.  
  2650. static void Nlm_NormalDrawChar (Nlm_GraphiC w, Nlm_Char ch, Nlm_Boolean savePort)
  2651.  
  2652. {
  2653.   Nlm_DisplaY     d;
  2654.   Nlm_WindowData  wdata;
  2655.  
  2656.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2657.   d = wdata.charDisplay;
  2658.   if (d != NULL) {
  2659.     Nlm_DoSendChar ((Nlm_GraphiC) d, ch, TRUE);
  2660.   }
  2661. }
  2662.  
  2663. static void Nlm_FloatingDrawChar (Nlm_GraphiC w, Nlm_Char ch, Nlm_Boolean savePort)
  2664.  
  2665. {
  2666.   Nlm_DisplaY     d;
  2667.   Nlm_WindowData  wdata;
  2668. #ifdef WIN_MAC
  2669.   Nlm_WindoW      nw;
  2670. #endif
  2671.  
  2672.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2673.   d = wdata.charDisplay;
  2674.   if (d != NULL) {
  2675.     Nlm_DoSendChar ((Nlm_GraphiC) d, ch, TRUE);
  2676.   } else {
  2677. #ifdef WIN_MAC
  2678.     nw = Nlm_NextVisWindow ((Nlm_WindoW) w);
  2679.     Nlm_DoSendChar ((Nlm_GraphiC) nw, ch, TRUE);
  2680. #endif
  2681. #ifdef WIN_MOTIF
  2682. #endif
  2683.   }
  2684. }
  2685.  
  2686. static void Nlm_AdjustWindow (Nlm_GraphiC w, Nlm_RectPtr r,
  2687.                               Nlm_Boolean align, Nlm_Boolean savePort)
  2688.  
  2689. {
  2690.   Nlm_GraphiC  g;
  2691.   Nlm_WindoW   tempPort;
  2692.  
  2693.   tempPort = Nlm_SavePortIfNeeded (w, savePort);
  2694.   if (align) {
  2695.     g = Nlm_GetParent (w);
  2696.     Nlm_RecordRect (g, r);
  2697.     Nlm_NextPosition (g, r);
  2698.   }
  2699.   Nlm_RestorePort (tempPort);
  2700. }
  2701.  
  2702. static Nlm_GraphiC Nlm_WindowGainFocus (Nlm_GraphiC w, Nlm_Char ch, Nlm_Boolean savePort)
  2703.  
  2704. {
  2705.   Nlm_GraphiC  p;
  2706.   Nlm_GraphiC  q;
  2707.  
  2708.   q = NULL;
  2709.   p = Nlm_GetChild (w);
  2710.   while (p != NULL && q == NULL) {
  2711.     q = Nlm_DoGainFocus (p, ch, savePort);
  2712.     p = Nlm_GetNext (p);
  2713.   }
  2714.   return q;
  2715. }
  2716.  
  2717. static void Nlm_WindowLoseFocus (Nlm_GraphiC w, Nlm_GraphiC excpt, Nlm_Boolean savePort)
  2718.  
  2719. {
  2720.   Nlm_GraphiC  p;
  2721.  
  2722.   p = Nlm_GetChild (w);
  2723.   while (p != NULL) {
  2724.     Nlm_DoLoseFocus (p, excpt, savePort);
  2725.     p = Nlm_GetNext (p);
  2726.   }
  2727. }
  2728.  
  2729. extern Nlm_WindoW Nlm_DocumentWindow (Nlm_Int2 left, Nlm_Int2 top,
  2730.                                       Nlm_Int2 width, Nlm_Int2 height,
  2731.                                       Nlm_CharPtr title,
  2732.                                       Nlm_WndActnProc close,
  2733.                                       Nlm_WndActnProc resize)
  2734.  
  2735. {
  2736.   Nlm_RecT    r;
  2737.   Nlm_WindoW  w;
  2738.  
  2739.   Nlm_LoadRect (&r, left, top, width, height);
  2740.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), documentProcs);
  2741.   if (w != NULL) {
  2742. #ifdef WIN_MAC
  2743.     Nlm_NewWindow (w, DOCUMENT_STYLE, 8, TRUE, NULL, 0, title, close, resize);
  2744. #endif
  2745. #ifdef WIN_MSWIN
  2746.     Nlm_NewWindow (w, DOCUMENT_STYLE, 0, FALSE, windowclass, WS_OVERLAPPEDWINDOW, title, close, resize);
  2747. #endif
  2748. #ifdef WIN_MOTIF
  2749.     Nlm_NewWindow (w, DOCUMENT_STYLE, 0, FALSE, NULL, 0, title, close, resize);
  2750. #endif
  2751.   }
  2752.   return w;
  2753. }
  2754.  
  2755. extern Nlm_WindoW Nlm_FixedWindow (Nlm_Int2 left, Nlm_Int2 top,
  2756.                                    Nlm_Int2 width, Nlm_Int2 height,
  2757.                                    Nlm_CharPtr title, Nlm_WndActnProc close)
  2758.  
  2759. {
  2760.   Nlm_RecT    r;
  2761.   Nlm_WindoW  w;
  2762.  
  2763.   Nlm_LoadRect (&r, left, top, width, height);
  2764.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), fixedProcs);
  2765.   if (w != NULL) {
  2766. #ifdef WIN_MAC
  2767.     Nlm_NewWindow (w, FIXED_STYLE, 4, TRUE, NULL, 0, title, close, NULL);
  2768. #endif
  2769. #ifdef WIN_MSWIN
  2770.     Nlm_NewWindow (w, FIXED_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED |
  2771.                    WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, title, close, NULL);
  2772. #endif
  2773. #ifdef WIN_MOTIF
  2774.     Nlm_NewWindow (w, FIXED_STYLE, 0, FALSE, NULL, 0, title, close, NULL);
  2775. #endif
  2776.   }
  2777.   return w;
  2778. }
  2779.  
  2780. extern Nlm_WindoW Nlm_FrozenWindow (Nlm_Int2 left, Nlm_Int2 top,
  2781.                                     Nlm_Int2 width, Nlm_Int2 height,
  2782.                                     Nlm_CharPtr title, Nlm_WndActnProc close)
  2783.  
  2784. {
  2785.   Nlm_RecT    r;
  2786.   Nlm_WindoW  w;
  2787.  
  2788.   Nlm_LoadRect (&r, left, top, width, height);
  2789.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), frozenProcs);
  2790.   if (w != NULL) {
  2791. #ifdef WIN_MAC
  2792.     Nlm_NewWindow (w, FROZEN_STYLE, 4, TRUE, NULL, 0, title, close, NULL);
  2793. #endif
  2794. #ifdef WIN_MSWIN
  2795.     Nlm_NewWindow (w, FROZEN_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED |
  2796.                    WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, title, close, NULL);
  2797. #endif
  2798. #ifdef WIN_MOTIF
  2799.     Nlm_NewWindow (w, FROZEN_STYLE, 0, FALSE, NULL, 0, title, close, NULL);
  2800. #endif
  2801.   }
  2802.   return w;
  2803. }
  2804.  
  2805. extern Nlm_WindoW Nlm_RoundWindow (Nlm_Int2 left, Nlm_Int2 top,
  2806.                                    Nlm_Int2 width, Nlm_Int2 height,
  2807.                                    Nlm_CharPtr title, Nlm_WndActnProc close)
  2808.  
  2809. {
  2810.   Nlm_RecT    r;
  2811.   Nlm_WindoW  w;
  2812.  
  2813.   Nlm_LoadRect (&r, left, top, width, height);
  2814.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), roundProcs);
  2815.   if (w != NULL) {
  2816. #ifdef WIN_MAC
  2817.     Nlm_NewWindow (w, ROUND_STYLE, 16, TRUE, NULL, 0, title, close, NULL);
  2818. #endif
  2819. #ifdef WIN_MSWIN
  2820.     Nlm_NewWindow (w, ROUND_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED |
  2821.                    WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, title, close, NULL);
  2822. #endif
  2823. #ifdef WIN_MOTIF
  2824.     Nlm_NewWindow (w, ROUND_STYLE, 0, FALSE, NULL, 0, title, close, NULL);
  2825. #endif
  2826.   }
  2827.   return w;
  2828. }
  2829.  
  2830. extern Nlm_WindoW Nlm_AlertWindow (Nlm_Int2 left, Nlm_Int2 top,
  2831.                                    Nlm_Int2 width, Nlm_Int2 height,
  2832.                                    Nlm_WndActnProc close)
  2833.  
  2834. {
  2835.   Nlm_RecT    r;
  2836.   Nlm_WindoW  w;
  2837.  
  2838.   Nlm_LoadRect (&r, left, top, width, height);
  2839.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), alertProcs);
  2840.   if (w != NULL) {
  2841. #ifdef WIN_MAC
  2842.     Nlm_NewWindow (w, ALERT_STYLE, 1, FALSE, NULL, 0, NULL, close, NULL);
  2843. #endif
  2844. #ifdef WIN_MSWIN
  2845.     Nlm_NewWindow (w, ALERT_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED, "", close, NULL);
  2846. #endif
  2847. #ifdef WIN_MOTIF
  2848.     Nlm_NewWindow (w, ALERT_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2849. #endif
  2850.   }
  2851.   return w;
  2852. }
  2853.  
  2854. extern Nlm_WindoW Nlm_ModalWindow (Nlm_Int2 left, Nlm_Int2 top,
  2855.                                    Nlm_Int2 width, Nlm_Int2 height,
  2856.                                    Nlm_WndActnProc close)
  2857.  
  2858. {
  2859.   Nlm_RecT    r;
  2860.   Nlm_WindoW  w;
  2861.  
  2862.   Nlm_LoadRect (&r, left, top, width, height);
  2863.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), modalProcs);
  2864.   if (w != NULL) {
  2865. #ifdef WIN_MAC
  2866.     Nlm_NewWindow (w, MODAL_STYLE, 1, FALSE, NULL, 0, NULL, close, NULL);
  2867. #endif
  2868. #ifdef WIN_MSWIN
  2869.     Nlm_NewWindow (w, MODAL_STYLE, 0, FALSE, windowclass, WS_POPUP |
  2870.                    WS_CAPTION | WS_SYSMENU, "", close, NULL);
  2871. #endif
  2872. #ifdef WIN_MOTIF
  2873.     Nlm_NewWindow (w, MODAL_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2874. #endif
  2875.   }
  2876.   return w;
  2877. }
  2878.  
  2879. extern Nlm_WindoW Nlm_FloatingWindow (Nlm_Int2 left, Nlm_Int2 top,
  2880.                                       Nlm_Int2 width, Nlm_Int2 height,
  2881.                                       Nlm_WndActnProc close)
  2882.  
  2883. {
  2884.   Nlm_RecT    r;
  2885.   Nlm_WindoW  w;
  2886.  
  2887.   Nlm_LoadRect (&r, left, top, width, height);
  2888.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), floatingProcs);
  2889.   if (w != NULL) {
  2890. #ifdef WIN_MAC
  2891.     Nlm_NewWindow (w, FLOATING_STYLE, 17, TRUE, NULL, 0, NULL, close, NULL);
  2892. #endif
  2893. #ifdef WIN_MSWIN
  2894.     Nlm_NewWindow (w, FLOATING_STYLE, 0, FALSE, windowclass, WS_POPUP |
  2895.                    WS_CAPTION | WS_SYSMENU, "", close, NULL);
  2896. #endif
  2897. #ifdef WIN_MOTIF
  2898.     Nlm_NewWindow (w, FLOATING_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2899. #endif
  2900.   }
  2901.   return w;
  2902. }
  2903.  
  2904. extern Nlm_WindoW Nlm_ShadowWindow (Nlm_Int2 left, Nlm_Int2 top,
  2905.                                     Nlm_Int2 width, Nlm_Int2 height,
  2906.                                     Nlm_WndActnProc close)
  2907.  
  2908. {
  2909.   Nlm_RecT    r;
  2910.   Nlm_WindoW  w;
  2911.  
  2912.   Nlm_LoadRect (&r, left, top, width, height);
  2913.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), shadowProcs);
  2914.   if (w != NULL) {
  2915. #ifdef WIN_MAC
  2916.     Nlm_NewWindow (w, SHADOW_STYLE, 3, FALSE, NULL, 0, NULL, close, NULL);
  2917. #endif
  2918. #ifdef WIN_MSWIN
  2919.     Nlm_NewWindow (w, SHADOW_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED, "", close, NULL);
  2920. #endif
  2921. #ifdef WIN_MOTIF
  2922.     Nlm_NewWindow (w, SHADOW_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2923. #endif
  2924.   }
  2925.   return w;
  2926. }
  2927.  
  2928. extern Nlm_WindoW Nlm_PlainWindow (Nlm_Int2 left, Nlm_Int2 top,
  2929.                                    Nlm_Int2 width, Nlm_Int2 height,
  2930.                                    Nlm_WndActnProc close)
  2931.  
  2932. {
  2933.   Nlm_RecT    r;
  2934.   Nlm_WindoW  w;
  2935.  
  2936.   Nlm_LoadRect (&r, left, top, width, height);
  2937.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), plainProcs);
  2938.   if (w != NULL) {
  2939. #ifdef WIN_MAC
  2940.     Nlm_NewWindow (w, PLAIN_STYLE, 2, FALSE, NULL, 0, NULL, close, NULL);
  2941. #endif
  2942. #ifdef WIN_MSWIN
  2943.     Nlm_NewWindow (w, PLAIN_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED, "", close, NULL);
  2944. #endif
  2945. #ifdef WIN_MOTIF
  2946.     Nlm_NewWindow (w, PLAIN_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2947. #endif
  2948.   }
  2949.   return w;
  2950. }
  2951.  
  2952. #ifdef WIN_MOTIF
  2953. static void Nlm_SetCursor (Cursor cursor)
  2954.  
  2955. {
  2956.   Nlm_MainTool  man;
  2957.   Nlm_WindoW    w;
  2958.   Window        xtw;
  2959.  
  2960.   if (Nlm_currentXDisplay != NULL) {
  2961.     w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  2962.     while (w != NULL) {
  2963.       if (! Nlm_IsWindowDying (w)) {
  2964.         man = Nlm_GetWindowMain (w);
  2965.         xtw = XtWindow (man);
  2966.         if (xtw != 0) {
  2967.           XDefineCursor (Nlm_currentXDisplay, xtw, cursor);
  2968.         }
  2969.       }
  2970.       w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  2971.     }
  2972.     currentCursor = cursor;
  2973.     XSync (Nlm_currentXDisplay, FALSE);
  2974.   }
  2975. }
  2976. #endif
  2977.  
  2978. extern void Nlm_ArrowCursor (void)
  2979.  
  2980. {
  2981. #ifdef WIN_MAC
  2982.   SetCursor (&qd.arrow);
  2983. #endif
  2984. #ifdef WIN_MSWIN
  2985.   currentCursor = LoadCursor (NULL, IDC_ARROW);
  2986.   SetCursor (currentCursor);
  2987. #endif
  2988. #ifdef WIN_MOTIF
  2989.   Nlm_SetCursor (arrow);
  2990. #endif
  2991. }
  2992.  
  2993. extern void Nlm_CrossCursor (void)
  2994.  
  2995. {
  2996. #ifdef WIN_MAC
  2997.   SetCursor (&cross);
  2998. #endif
  2999. #ifdef WIN_MSWIN
  3000.   currentCursor = LoadCursor (NULL, IDC_CROSS);
  3001.   SetCursor (currentCursor);
  3002. #endif
  3003. #ifdef WIN_MOTIF
  3004.   Nlm_SetCursor (cross);
  3005. #endif
  3006. }
  3007.  
  3008. extern void Nlm_IBeamCursor (void)
  3009.  
  3010. {
  3011. #ifdef WIN_MAC
  3012.   SetCursor (&iBeam);
  3013. #endif
  3014. #ifdef WIN_MSWIN
  3015.   currentCursor = LoadCursor (NULL, IDC_IBEAM);
  3016.   SetCursor (currentCursor);
  3017. #endif
  3018. #ifdef WIN_MOTIF
  3019.   Nlm_SetCursor (iBeam);
  3020. #endif
  3021. }
  3022.  
  3023. extern void Nlm_PlusCursor (void)
  3024.  
  3025. {
  3026. #ifdef WIN_MAC
  3027.   SetCursor (&plus);
  3028. #endif
  3029. #ifdef WIN_MSWIN
  3030.   currentCursor = LoadCursor (NULL, IDC_CROSS);
  3031.   SetCursor (currentCursor);
  3032. #endif
  3033. #ifdef WIN_MOTIF
  3034.   Nlm_SetCursor (plus);
  3035. #endif
  3036. }
  3037.  
  3038. extern void Nlm_WatchCursor (void)
  3039.  
  3040. {
  3041. #ifdef WIN_MAC
  3042.   SetCursor (&watch);
  3043. #endif
  3044. #ifdef WIN_MSWIN
  3045.   currentCursor = LoadCursor (NULL, IDC_WAIT);
  3046.   SetCursor (currentCursor);
  3047. #endif
  3048. #ifdef WIN_MOTIF
  3049.   Nlm_SetCursor (watch);
  3050. #endif
  3051. }
  3052.  
  3053.  
  3054. #ifdef DCLAP
  3055. Nlm_Char    gProgramPath[PATH_MAX];  
  3056. Nlm_Char        gProgramName[PATH_MAX];
  3057. #endif
  3058.  
  3059. extern void Nlm_ProgramPath (Nlm_CharPtr buf, Nlm_sizeT maxsize)
  3060.  
  3061. {
  3062. #ifdef WIN_MAC
  3063.   WDPBRec      block;
  3064.   Nlm_Char     directory [PATH_MAX];
  3065.   Nlm_Int4     dirID;
  3066.   OSErr        err;
  3067.   CInfoPBRec   params;
  3068.   Nlm_Char     temp [PATH_MAX]; 
  3069.   Nlm_CharPtr  tmp;
  3070.   short        vRefNum;
  3071. #endif
  3072. #ifdef WIN_MSWIN
  3073.   Nlm_Char     path [PATH_MAX];
  3074. #endif
  3075. #ifdef WIN_MOTIF
  3076.   Nlm_Char     path [PATH_MAX];
  3077.   Nlm_CharPtr  pth;
  3078.   Nlm_CharPtr  ptr, progname;
  3079. #endif
  3080.  
  3081.   if (buf != NULL && maxsize > 0) {
  3082. #ifdef DCLAP
  3083.         if (*gProgramPath) {
  3084.             Nlm_StringNCpy (buf, gProgramPath, maxsize);
  3085.             return;
  3086.             }
  3087. #endif
  3088.  
  3089. #ifdef WIN_MAC
  3090.     memset (&block, 0, sizeof (WDPBRec));
  3091.     block.ioNamePtr = NULL;
  3092.     block.ioVRefNum = apRefNum;
  3093.     block.ioWDIndex = 0;
  3094.     block.ioWDProcID = 0;
  3095.     PBGetWDInfo (&block, FALSE); /* ! this won't work after a StdOpen or other WD changer !! */
  3096.     dirID = block.ioWDDirID;
  3097.     vRefNum = block.ioWDVRefNum;
  3098.     temp [0] = '\0';
  3099.     params.dirInfo.ioNamePtr = (StringPtr) directory;
  3100.     params.dirInfo.ioDrParID = dirID;
  3101.     do {
  3102.       params.dirInfo.ioVRefNum = vRefNum;
  3103.       params.dirInfo.ioFDirIndex = -1;
  3104.       params.dirInfo.ioDrDirID = params.dirInfo.ioDrParID;
  3105.       err = PBGetCatInfo (¶ms, FALSE);
  3106. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  3107.   p2cstr ((StringPtr) directory);
  3108. #endif
  3109. #ifdef COMP_THINKC
  3110.   PtoCstr ((StringPtr) directory);
  3111. #endif
  3112.       Nlm_StringCat (directory, DIRDELIMSTR);
  3113.       Nlm_StringCat (directory, temp);
  3114.       Nlm_StringCpy (temp, directory);
  3115.     } while (params.dirInfo.ioDrDirID != fsRtDirID);
  3116.     tmp = Nlm_StringMove (directory, temp);
  3117.     tmp = Nlm_StringMove (tmp, (Nlm_CharPtr) apName);
  3118.     Nlm_StringNCpy (buf, directory, maxsize);
  3119. #endif
  3120. #ifdef WIN_MSWIN
  3121.     if (GetModuleFileName (Nlm_currentHInst, path, sizeof (path)) > 0) {
  3122.       Nlm_StringNCpy (buf, path, maxsize);
  3123.     } else {
  3124.       *buf = '\0';
  3125.     }
  3126. #endif
  3127. #ifdef OS_UNIX
  3128.     ptr = statargv [0];
  3129. #ifdef DCLAP
  3130.         if (*gProgramName) progname= gProgramName;
  3131.         else progname= NULL;
  3132. #endif
  3133.     if (ptr [0] == DIRDELIMCHR) {
  3134.       Nlm_StringNCpy (buf, statargv [0], maxsize);
  3135. #ifdef DCLAP
  3136.             if (!progname) {
  3137.                 progname= ptr + Nlm_StrLen(ptr);
  3138.                 do { --progname; }
  3139.                 while (progname > ptr && progname[-1] != DIRDELIMCHR);
  3140.                 }
  3141. #endif
  3142.         } 
  3143.  
  3144.         else if (getcwd (path, sizeof (path)) != NULL) {
  3145.             /* this will FAIL for program run from PATH !! - dgg*/
  3146.       ptr = statargv [0];
  3147.       while (ptr [0] == '.' || ptr [0] == DIRDELIMCHR) {
  3148.         if (ptr [0] == '.') {
  3149.           if (ptr [1] == '.' && ptr [2] == DIRDELIMCHR) {
  3150.             ptr += 3;
  3151.             pth = StringRChr (path, DIRDELIMCHR);
  3152.             if (pth != NULL) {
  3153.               *pth = '\0';
  3154.             }
  3155.           } else if (ptr [1] == DIRDELIMCHR) {
  3156.             ptr += 2;
  3157.           } else {
  3158.             ptr++;
  3159.           }
  3160.         } else if (ptr [0] == DIRDELIMCHR) {
  3161.           ptr++;
  3162.         } else {
  3163.           ptr++;
  3164.         }
  3165.       }
  3166. #ifdef DCLAP
  3167.             if (!progname) progname= ptr;
  3168. #endif
  3169.       FileBuildPath (path, NULL, ptr);
  3170.       Nlm_StringNCpy (buf, path, maxsize);
  3171.     } else {
  3172.       Nlm_StringNCpy (buf, statargv [0], maxsize);
  3173. #ifdef DCLAP
  3174.             if (!progname) progname= ptr;
  3175. #endif
  3176.     }
  3177.  
  3178. #ifdef DCLAP    
  3179.             {    
  3180.             char * apath, envname[64];
  3181.             if (!progname) progname= "DCLAP";
  3182.       Nlm_StringNCpy(envname, progname, 64);
  3183.             Nlm_StringUpper(envname);
  3184.       Nlm_StringNCat(envname,"HOME", 64);
  3185.             apath= getenv( envname);
  3186.             if (apath) {
  3187.                 Nlm_StringNCpy( path, apath, maxsize);
  3188.           FileBuildPath (path, NULL, ptr);
  3189.                 Nlm_StringNCpy( buf, path, maxsize);
  3190.                 }
  3191.             }
  3192. #endif
  3193. #endif
  3194.  
  3195. #ifdef OS_VMS
  3196.     if (statargv != NULL && statargv [0] != NULL) {
  3197.       Nlm_StringNCpy (buf, statargv [0], maxsize);
  3198.     }
  3199. #endif
  3200. #ifdef DCLAP
  3201.     if (buf[0]) Nlm_StringNCpy(gProgramPath, buf, PATH_MAX);
  3202. #endif
  3203.   }
  3204. }
  3205.  
  3206. #ifdef WIN_MAC
  3207.  
  3208. static void Nlm_HandleEvent (void)
  3209.  
  3210. {
  3211.   Nlm_Int2        key;
  3212.   Nlm_PointTool   ptool;
  3213.   Nlm_PoinT       where;
  3214.   Nlm_Int2        windowLoc;
  3215.   Nlm_WindowTool  wptr;
  3216.  
  3217.   Nlm_PointToolToPoinT (Nlm_currentEvent.where, &Nlm_globalMouse);
  3218.   Nlm_localMouse = Nlm_globalMouse;
  3219.   Nlm_GlobalToLocal (&Nlm_localMouse);
  3220.   Nlm_currentKey = '\0';
  3221.   key = Nlm_currentEvent.modifiers;
  3222.   Nlm_cmmdKey = ((key & 256) != 0);
  3223.   Nlm_ctrlKey = FALSE;
  3224.   Nlm_shftKey = ((key & 512) != 0);
  3225.   Nlm_optKey = ((key & 2048) != 0);
  3226.   Nlm_dblClick = FALSE;
  3227.   frontWindow = Nlm_FindWindowRec (FrontWindow ());
  3228.   Nlm_theWindow = Nlm_FindWindowRec ((Nlm_WindowTool) Nlm_currentEvent.message);
  3229.   chosenWindow = Nlm_theWindow;
  3230.   switch (Nlm_currentEvent.what) {
  3231.     case mouseDown:
  3232.       Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  3233.       windowLoc = FindWindow (ptool, &wptr);
  3234.       chosenWindow = Nlm_FindWindowRec (wptr);
  3235.       Nlm_DoClick ((Nlm_GraphiC) frontWindow, Nlm_globalMouse);
  3236.       break;
  3237.     case keyDown:
  3238.       Nlm_currentKey = (Nlm_Char) (Nlm_currentEvent.message % 256);
  3239.       if (keyAction != NULL) {
  3240.         keyAction (Nlm_currentKey);
  3241.       }
  3242.       Nlm_DoKey ((Nlm_GraphiC) frontWindow, Nlm_currentKey);
  3243.       break;
  3244.     case autoKey:
  3245.       if (! Nlm_cmmdKey) {
  3246.         Nlm_currentKey = (Nlm_Char) (Nlm_currentEvent.message % 256);
  3247.         Nlm_DoKey ((Nlm_GraphiC) frontWindow, Nlm_currentKey);
  3248.       }
  3249.       break;
  3250.     case updateEvt:
  3251.       Nlm_DoDraw ((Nlm_GraphiC) Nlm_theWindow);
  3252.       break;
  3253.     case osEvt:
  3254.       if (((Nlm_currentEvent.message & osEvtMessageMask) >> 24) == suspendResumeMessage) {
  3255.         if (Nlm_currentEvent.message & resumeFlag) {
  3256.           if (Nlm_currentEvent.message & convertClipboardFlag) {
  3257.             TEFromScrap ();
  3258.           }
  3259.         } else {
  3260.           ZeroScrap ();
  3261.           TEToScrap ();
  3262.         }
  3263.       }
  3264.       break;
  3265.     case activateEvt:
  3266.       if (Nlm_currentEvent.modifiers & 01) {
  3267.         Nlm_DoActivate ((Nlm_GraphiC) Nlm_theWindow, FALSE);
  3268.       } else {
  3269.         Nlm_DoDeactivate ((Nlm_GraphiC) Nlm_theWindow, FALSE);
  3270.       }
  3271.       break;
  3272.     case diskEvt:
  3273.       if (HiWord (Nlm_currentEvent.message) != 0) {
  3274.         where.x = 90;
  3275.         where.y = 100;
  3276.         Nlm_PoinTToPointTool (where, &ptool);
  3277.         DIBadMount (ptool, Nlm_currentEvent.message);
  3278.       }
  3279.       break;
  3280.     case kHighLevelEvent:
  3281. #ifdef DCLAP
  3282.                 // 68k mac app is bombing here now (not before) ... ?? why
  3283.             if (StrNCmp((char*)&Nlm_currentEvent.where.v,"oapp",4)==0) break;
  3284. #endif
  3285.       AEProcessAppleEvent (&Nlm_currentEvent);
  3286.       break;
  3287.     default:
  3288.       break;
  3289.   }
  3290. }
  3291.  
  3292. extern Nlm_Boolean Nlm_RegisterWindows (void)
  3293.  
  3294. {
  3295.   return TRUE;
  3296. }
  3297.  
  3298. static void Nlm_ReturnCursor (Cursor *cursor, Nlm_Int2 cursorID)
  3299.  
  3300. {
  3301.   CursHandle  hCurs;
  3302.   CursPtr     pCurs;
  3303.  
  3304.   hCurs = GetCursor (cursorID);
  3305.   if (hCurs != NULL) {
  3306.     HLock ((Handle) hCurs);
  3307.     pCurs = (CursPtr) *((Handle) hCurs);
  3308.     *cursor = *pCurs;
  3309.     HUnlock ((Handle) hCurs);
  3310.   } else {
  3311.     *cursor = qd.arrow;
  3312.   }
  3313. }
  3314.  
  3315. static Nlm_Boolean Nlm_SetupWindows (void)
  3316.  
  3317. {
  3318.   Nlm_PoinT  pt;
  3319.   Nlm_RecT   r;
  3320.   SysEnvRec  sysenv;
  3321.  
  3322.   Nlm_ReturnCursor (&cross, 2);
  3323.   Nlm_ReturnCursor (&iBeam, 1);
  3324.   Nlm_ReturnCursor (&plus, 3);
  3325.   Nlm_ReturnCursor (&watch, 4);
  3326.   Nlm_WatchCursor ();
  3327.   Nlm_ClearKeys ();
  3328.   Nlm_LoadPt (&pt, 0, 0);
  3329.   Nlm_RectToolToRecT (&(qd.screenBits.bounds), &screenBitBounds);
  3330.   r = screenBitBounds;
  3331.   Nlm_screenRect = screenBitBounds;
  3332.   Nlm_desktopWindow = (Nlm_WindoW) Nlm_HandNew (sizeof (Nlm_WindowRec));
  3333.   Nlm_systemWindow = (Nlm_WindoW) Nlm_HandNew (sizeof (Nlm_WindowRec));
  3334.   Nlm_LoadGraphicData ((Nlm_GraphiC) Nlm_desktopWindow, (Nlm_GraphiC) Nlm_systemWindow,
  3335.                        NULL, NULL, NULL, desktopProcs, NULL, &r, TRUE, TRUE);
  3336.   Nlm_LoadBoxData ((Nlm_BoX) Nlm_desktopWindow, pt, pt, pt, 0, 0, 0, 0, 0, 0, 0, 0);
  3337.   Nlm_LoadWindowData (Nlm_desktopWindow, NULL, NULL, NULL, NULL, &r, &r, &r, NULL,
  3338.                       NULL, NULL, NULL, NULL, NULL, NULL, TRUE, FALSE, NULL, NULL, NULL);
  3339.   Nlm_LoadRect (&r, 0, 0, 0, 0);
  3340.   Nlm_LoadGraphicData ((Nlm_GraphiC) Nlm_systemWindow, NULL, NULL,
  3341.                        NULL, NULL, systemProcs, NULL, &r, TRUE, TRUE);
  3342.   Nlm_LoadBoxData ((Nlm_BoX) Nlm_systemWindow, pt, pt, pt, 0, 0, 0, 0, 0, 0, 0, 0);
  3343.   Nlm_LoadWindowData (Nlm_systemWindow, NULL, NULL, NULL, NULL, &r, &r, &r, NULL,
  3344.                       NULL, NULL, NULL, NULL, NULL, NULL, TRUE, FALSE, NULL, NULL, NULL);
  3345.   dyingWindow = NULL;
  3346.   frontWindow = Nlm_desktopWindow;
  3347.   theActiveWindow = Nlm_desktopWindow;
  3348.   chosenWindow = Nlm_desktopWindow;
  3349.   Nlm_theWindow = Nlm_desktopWindow;
  3350.   Nlm_currentWindowTool = NULL;
  3351.   quitProgram = FALSE;
  3352.  
  3353.   Nlm_SetUpDrawingTools ();
  3354.  
  3355.   Nlm_hScrollBarHeight = 16;
  3356.   Nlm_vScrollBarWidth = 16;
  3357.  
  3358.   Nlm_popupMenuHeight = Nlm_stdLineHeight + 4;
  3359.   Nlm_dialogTextHeight = Nlm_stdLineHeight + 4;
  3360.   
  3361.   lastTimerTime = Nlm_ComputerTime ();
  3362.   timerAction = NULL;
  3363.   keyAction = NULL;
  3364.   SysEnvirons (1, &sysenv);
  3365.   hasColorQD = sysenv.hasColorQD;
  3366.   return TRUE;
  3367. }
  3368. #endif
  3369.  
  3370. #ifdef WIN_MSWIN
  3371.  
  3372. /* Message cracker functions */
  3373.  
  3374. static void MyCls_OnMouseMove (HWND hwnd, int x, int y, UINT keyFlags)
  3375.  
  3376. {
  3377.   SetCursor (currentCursor);
  3378. }
  3379.  
  3380. static void MyCls_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  3381.  
  3382. {
  3383.   Nlm_GraphiC  g;
  3384.   Nlm_MenuBaR  mb;
  3385.  
  3386.   Nlm_currentId = id;
  3387.   Nlm_currentHwndCtl = hwndCtl;
  3388.   Nlm_currentCode = codeNotify;
  3389.  
  3390.   if (hwndCtl == NULL) {
  3391. #ifdef DCLAP
  3392.         if (!Nlm_menuHwnd) Nlm_menuHwnd= Nlm_GetWindowPtr(Nlm_theWindow);
  3393. #endif
  3394.     mb = Nlm_GetWindowMenuBar (Nlm_theWindow);
  3395.     Nlm_DoCommand ((Nlm_GraphiC) mb);
  3396.   } else {
  3397.     g = (Nlm_GraphiC) GetProp (hwndCtl, (LPSTR) "Nlm_VibrantProp");
  3398.     (void) (Nlm_GetEnabled (g) &&
  3399.             Nlm_GetVisible (g) &&
  3400.             Nlm_DoCommand (g));
  3401.   }
  3402. }
  3403.  
  3404. static void MyCls_OnHVScroll (HWND hwnd, HWND hwndCtl, UINT code, int pos)
  3405.  
  3406. {
  3407.   Nlm_GraphiC  g;
  3408.  
  3409.   Nlm_currentHwndCtl = hwndCtl;
  3410.   Nlm_currentCode = code;
  3411.   Nlm_currentPos = pos;
  3412.  
  3413.   if (hwndCtl != NULL) {
  3414.     g = (Nlm_GraphiC) GetProp (hwndCtl, (LPSTR) "Nlm_VibrantProp");
  3415.     (void) (Nlm_GetEnabled (g) &&
  3416.             Nlm_GetVisible (g) &&
  3417.             Nlm_DoCommand (g));
  3418.   }
  3419. }
  3420.  
  3421. static void MyCls_OnClose (HWND hwnd)
  3422.  
  3423. {
  3424.   Nlm_WndActnProc  cls;
  3425.   Nlm_WindowData   wdata;
  3426.  
  3427.   Nlm_GetWindowData (Nlm_theWindow, &wdata);
  3428.   cls = wdata.close;
  3429.   if (cls != NULL) {
  3430.     cls (Nlm_theWindow);
  3431.   }
  3432. }
  3433.  
  3434. static void MyCls_OnActivate (HWND hwnd, UINT state, HWND hwndActDeact, BOOL fMinimized)
  3435.  
  3436. {
  3437.   if (state != 0) {
  3438.     Nlm_DoActivate ((Nlm_GraphiC) Nlm_theWindow, FALSE);
  3439.   } else {
  3440.     Nlm_DoDeactivate ((Nlm_GraphiC) Nlm_theWindow, FALSE);
  3441.   }
  3442. }
  3443.  
  3444. static void MyCls_OnSize (HWND hwnd, UINT state, int cx, int cy)
  3445.  
  3446. {
  3447.   Nlm_RecT         r;
  3448.   Nlm_WndActnProc  resize;
  3449.   Nlm_RectTool     rtool;
  3450.   Nlm_WindowData   wdata;
  3451.  
  3452.   if (Nlm_WindowHasBeenShown (Nlm_theWindow) &&
  3453.       Nlm_GetVisible ((Nlm_GraphiC) Nlm_theWindow)) {
  3454.     Nlm_GetWindowData (Nlm_theWindow, &wdata);
  3455.     resize = wdata.resize;
  3456.     if (resize != NULL) {
  3457.       GetWindowRect (hwnd, &rtool);
  3458.       Nlm_RectToolToRecT (&rtool, &r);
  3459.       Nlm_SetRect ((Nlm_GraphiC) Nlm_theWindow, &r);
  3460.       resize (Nlm_theWindow);
  3461.     }
  3462.   }
  3463. }
  3464.  
  3465. static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
  3466.  
  3467. {
  3468.   handlechar = FALSE;
  3469.   if (ch == '\t') {
  3470.     Nlm_DoSendFocus ((Nlm_GraphiC) Nlm_theWindow, (Nlm_Char) ch);
  3471.   } else if (ch == '\n' || ch == '\r') {
  3472.     Nlm_DoSendFocus ((Nlm_GraphiC) Nlm_theWindow, (Nlm_Char) ch);
  3473.   } else {
  3474.     handlechar = TRUE;
  3475.   }
  3476. }
  3477.  
  3478. /*
  3479. *  Note that the WM_SIZE message will trigger the resize callback whenever
  3480. *  a visible window is resized, including the initial sizing when a window
  3481. *  is first displayed.
  3482. */
  3483.  
  3484. LRESULT CALLBACK EXPORT MainProc (HWND hwnd, UINT message,
  3485.                                   WPARAM wParam, LPARAM lParam)
  3486.  
  3487. {
  3488.   MINMAXINFO FAR*  lpmmi;
  3489.   HDC              tempHDC;
  3490.   HWND             tempHWnd;
  3491.  
  3492.   if (Nlm_VibrantDisabled ()) {
  3493.     return DefWindowProc (hwnd, message, wParam, lParam);
  3494.   }
  3495.  
  3496.   mainwndrsult = 0;
  3497.   tempHWnd = Nlm_currentHWnd;
  3498.   tempHDC = Nlm_currentHDC;
  3499.   Nlm_theWindow = (Nlm_WindoW) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  3500.   Nlm_currentHWnd = hwnd;
  3501.   Nlm_currentHDC = Nlm_GetWindowPort (Nlm_theWindow);
  3502.   Nlm_currentWindowTool = hwnd;
  3503.   Nlm_currentKey = '\0';
  3504.   Nlm_currentWParam = wParam;
  3505.   Nlm_currentLParam = lParam;
  3506.   Nlm_cmmdKey = FALSE;
  3507.   Nlm_ctrlKey = FALSE;
  3508.   Nlm_optKey = FALSE;
  3509.   Nlm_shftKey = FALSE;
  3510.   Nlm_dblClick = FALSE;
  3511.   switch (message) {
  3512.     case WM_MOUSEMOVE:
  3513.       HANDLE_WM_MOUSEMOVE (hwnd, wParam, lParam, MyCls_OnMouseMove);
  3514.       break;
  3515.     case WM_COMMAND:
  3516.       HANDLE_WM_COMMAND (hwnd, wParam, lParam, MyCls_OnCommand);
  3517.       break;
  3518.     case WM_HSCROLL:
  3519.       HANDLE_WM_HSCROLL (hwnd, wParam, lParam, MyCls_OnHVScroll);
  3520.       break;
  3521.     case WM_VSCROLL:
  3522.       HANDLE_WM_VSCROLL (hwnd, wParam, lParam, MyCls_OnHVScroll);
  3523.       break;
  3524.     case WM_CLOSE:
  3525.       HANDLE_WM_CLOSE (hwnd, wParam, lParam, MyCls_OnClose);
  3526.       break;
  3527.     case WM_ACTIVATE:
  3528.       mainwndrsult = DefWindowProc (hwnd, message, wParam, lParam);
  3529.       HANDLE_WM_ACTIVATE (hwnd, wParam, lParam, MyCls_OnActivate);
  3530.       break;
  3531.     case WM_SIZE:
  3532.       HANDLE_WM_SIZE (hwnd, wParam, lParam, MyCls_OnSize);
  3533.       break;
  3534.     case WM_GETMINMAXINFO:
  3535.       lpmmi = (MINMAXINFO FAR*) lParam;
  3536.       lpmmi->ptMaxTrackSize.x = 30000;
  3537.       lpmmi->ptMaxTrackSize.y = 30000;
  3538.       break;
  3539.     case WM_DESTROY:
  3540.       break;
  3541. #if !defined(WIN32) && !defined(WIN32BOR)
  3542.     case WM_CTLCOLOR:
  3543.       if (lParam == CTLCOLOR_STATIC || lParam == CTLCOLOR_LISTBOX ||
  3544.           lParam == CTLCOLOR_EDIT || lParam == CTLCOLOR_BTN) {
  3545.         mainwndrsult = (long) (int) GetStockObject (WHITE_BRUSH);
  3546.         SetBkColor ((HDC) wParam, RGB (255, 255, 255));
  3547.         SetTextColor ((HDC) wParam, RGB (0, 0, 0));
  3548.       } else {
  3549.         mainwndrsult = DefWindowProc (hwnd, message, wParam, lParam);
  3550.       }
  3551.       break;
  3552. #else
  3553.     case WM_CTLCOLORSTATIC:
  3554.     case WM_CTLCOLORLISTBOX:
  3555.     case WM_CTLCOLOREDIT:
  3556.     case WM_CTLCOLORBTN:
  3557.       mainwndrsult = (long) GetStockObject (WHITE_BRUSH);
  3558.       SetBkColor ((HDC) wParam, RGB (255, 255, 255));
  3559.       SetTextColor ((HDC) wParam, RGB (0, 0, 0));
  3560.       break;
  3561. #endif
  3562.     case WM_CHAR:
  3563. #ifdef DCLAP
  3564.             /* Nlm_cmmdKey= (((unsigned long)lParam >> 29) & 1); /* alt key flag */
  3565. #endif
  3566.       HANDLE_WM_CHAR (hwnd, wParam, lParam, MyCls_OnChar);
  3567.       if (handlechar) {
  3568.         mainwndrsult = DefWindowProc (hwnd, message, wParam, lParam);
  3569.       }
  3570.       break;
  3571.     default:
  3572.       mainwndrsult = DefWindowProc (hwnd, message, wParam, lParam);
  3573.       break;
  3574.   }
  3575.   Nlm_currentHWnd = tempHWnd;
  3576.   Nlm_currentHDC = tempHDC;
  3577.   Nlm_currentWindowTool = tempHWnd;
  3578.   return mainwndrsult;
  3579. }
  3580.  
  3581. void FAR PASCAL EXPORT MetronomeProc (HWND hwnd, UINT message,
  3582.                                       WPARAM wParam, LPARAM lParam)
  3583.  
  3584. {
  3585.   if (Nlm_VibrantDisabled ()) {
  3586.     return;
  3587.   }
  3588.   if (message == WM_TIMER && timerAction != NULL) {
  3589.     timerAction ();
  3590.   }
  3591. }
  3592.  
  3593. extern Nlm_Boolean Nlm_RegisterWindows (void)
  3594.  
  3595. {
  3596.   Nlm_Boolean  rsult;
  3597.   WNDCLASS     wc;
  3598.  
  3599.   rsult = FALSE;
  3600.   wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
  3601.   wc.lpfnWndProc = MainProc;
  3602.   wc.cbClsExtra = 0;
  3603.   wc.cbWndExtra = 0;
  3604.   wc.hInstance = Nlm_currentHInst;
  3605.   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  3606.   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  3607.   /*
  3608.   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  3609.   */
  3610.   wc.hbrBackground = CreateSolidBrush (GetSysColor (COLOR_WINDOW));
  3611.   wc.lpszMenuName = NULL;
  3612.   sprintf (windowclass, "Nlm_WindowClass%ld", (long) (int) Nlm_currentHInst);
  3613.   wc.lpszClassName = windowclass;
  3614.   rsult = (Nlm_Boolean) RegisterClass (&wc);
  3615.   return rsult;
  3616. }
  3617.  
  3618. static Nlm_Boolean Nlm_SetupWindows (void)
  3619.  
  3620. {
  3621.   Nlm_Int2   height;
  3622.   WNDPROC    lpfnTimerProc;
  3623.   Nlm_PoinT  pt;
  3624.   Nlm_RecT   r;
  3625.   Nlm_Int2   width;
  3626.  
  3627.   width = GetSystemMetrics (SM_CXSCREEN);
  3628.   height = GetSystemMetrics (SM_CYSCREEN);
  3629.   Nlm_LoadRect (&screenBitBounds, 0, 0, width, height);
  3630.   Nlm_LoadPt (&pt, 0, 0);
  3631.   r = screenBitBounds;
  3632.   Nlm_screenRect = screenBitBounds;
  3633.   Nlm_desktopWindow = (Nlm_WindoW) Nlm_HandNew (sizeof (Nlm_WindowRec));
  3634.   Nlm_LoadGraphicData ((Nlm_GraphiC) Nlm_desktopWindow, NULL, NULL,
  3635.                        NULL, NULL, desktopProcs, NULL, &r, TRUE, TRUE);
  3636.   Nlm_LoadBoxData ((Nlm_BoX) Nlm_desktopWindow, pt, pt, pt, 0, 0, 0, 0, 0, 0, 0, 0);
  3637.   Nlm_LoadWindowData (Nlm_desktopWindow, NULL, NULL, NULL, NULL, &r, &r, &r, NULL,
  3638.                       NULL, NULL, NULL, NULL, NULL, NULL, TRUE, FALSE, NULL, NULL, NULL);
  3639.   Nlm_systemWindow = NULL;
  3640.   Nlm_currentHWnd = NULL;
  3641.   Nlm_currentHDC = NULL;
  3642.   Nlm_currentWindowTool = NULL;
  3643.   quitProgram = FALSE;
  3644.   
  3645.   Nlm_SetUpDrawingTools ();
  3646.  
  3647.   Nlm_hScrollBarHeight = GetSystemMetrics (SM_CYHSCROLL);
  3648.   Nlm_vScrollBarWidth = GetSystemMetrics (SM_CXVSCROLL);
  3649.  
  3650.   Nlm_popupMenuHeight = Nlm_stdLineHeight + 8;
  3651.   Nlm_dialogTextHeight = Nlm_stdFontHeight * 3 / 2;
  3652.   
  3653.   currentCursor = LoadCursor (NULL, IDC_WAIT);
  3654.   
  3655.   lpfnTimerProc = (WNDPROC) MakeProcInstance ((FARPROC) MetronomeProc, Nlm_currentHInst);
  3656.   if (lpfnTimerProc != NULL) {
  3657.     timerID = SetTimer (NULL, 1, 50, (TIMERPROC) lpfnTimerProc);
  3658.   }
  3659.   timerAction = NULL;
  3660.   keyAction = NULL;
  3661.   return TRUE;
  3662. }
  3663. #endif
  3664.  
  3665. #ifdef WIN_MOTIF
  3666. static void Nlm_WindowTimer (XtPointer client_data, XtIntervalId *id)
  3667.  
  3668. {
  3669.   if (! quitProgram) {
  3670.     windowTimer = XtAppAddTimeOut (Nlm_appContext, 50, Nlm_WindowTimer, NULL);
  3671.   }
  3672.   if (timerAction != NULL) {
  3673.     timerAction ();
  3674.   }
  3675. }
  3676.  
  3677. extern Nlm_Boolean Nlm_RegisterWindows (void)
  3678.  
  3679. {
  3680.   windowTimer = XtAppAddTimeOut (Nlm_appContext, 50, Nlm_WindowTimer, NULL);
  3681.   return TRUE;
  3682. }
  3683.  
  3684.  
  3685. extern XFontStruct *Nlm_XLoadQueryFont PROTO((Display *, Nlm_CharPtr, Nlm_Boolean));
  3686. static Nlm_Boolean Nlm_SetupWindows (void)
  3687.  
  3688. {
  3689.   char       appname [128];
  3690.   Nlm_Int4   height;
  3691.   Nlm_PoinT  pt;
  3692.   Nlm_RecT   r;
  3693.   Nlm_Int4   width;
  3694.  
  3695.   Nlm_desktopWindow = NULL;
  3696.   Nlm_systemWindow = NULL;
  3697.   Nlm_currentXDisplay = NULL;
  3698.   Nlm_currentXScreen = 0;
  3699.   Nlm_currentXWindow = 0;
  3700.   Nlm_currentXGC = NULL;
  3701.   Nlm_currentWindowTool = NULL;
  3702.   quitProgram = FALSE;
  3703.   timerAction = NULL;
  3704.   keyAction = NULL;
  3705.  
  3706.   XtToolkitInitialize ();
  3707.   Nlm_appContext = XtCreateApplicationContext ();
  3708.   if (Nlm_appContext == NULL) {
  3709.     return FALSE;
  3710.   }
  3711. #ifdef DCLAP
  3712.   XtAppSetFallbackResources( Nlm_appContext, colorXresources);
  3713. #endif
  3714.  
  3715.   Nlm_currentXDisplay = XOpenDisplay (NULL);
  3716.   if (Nlm_currentXDisplay == NULL) {
  3717.     fprintf (stderr, "Vibrant applications require X Windows\n");
  3718.     return FALSE;
  3719.   }
  3720.   Nlm_currentXScreen = DefaultScreen (Nlm_currentXDisplay);
  3721.   width =  DisplayWidth (Nlm_currentXDisplay, Nlm_currentXScreen);
  3722.   height = DisplayHeight (Nlm_currentXDisplay, Nlm_currentXScreen);
  3723.  
  3724.   Nlm_LoadRect (&screenBitBounds, 0, 0, (Nlm_Int2) width, (Nlm_Int2) height);
  3725.   Nlm_LoadPt (&pt, 0, 0);
  3726.   r = screenBitBounds;
  3727.   Nlm_screenRect = screenBitBounds;
  3728.   Nlm_desktopWindow = (Nlm_WindoW) Nlm_HandNew (sizeof (Nlm_WindowRec));
  3729.   Nlm_LoadGraphicData ((Nlm_GraphiC) Nlm_desktopWindow, NULL, NULL,
  3730.                        NULL, NULL, desktopProcs, NULL, &r, TRUE, TRUE);
  3731.   Nlm_LoadBoxData ((Nlm_BoX) Nlm_desktopWindow, pt, pt, pt, 0, 0, 0, 0, 0, 0, 0, 0);
  3732.   Nlm_LoadWindowData (Nlm_desktopWindow, NULL, NULL, NULL, NULL, &r, &r, &r, NULL,
  3733.                       NULL, NULL, NULL, NULL, NULL, NULL, TRUE, FALSE, NULL, NULL, NULL);
  3734.   Nlm_StringNCpy (appname, statargv [0], sizeof (appname));
  3735.   TO_UPPER (appname [0]);
  3736.  
  3737. #ifdef DCLAP
  3738.   Nlm_StringNCpy (Nlm_appname, appname, sizeof (Nlm_appname));
  3739. #endif
  3740.  
  3741.   XtDisplayInitialize (Nlm_appContext, Nlm_currentXDisplay, (String) appname,
  3742.                        (String) "Vibrant", (XrmOptionDescRec *) NULL,
  3743.                        (Cardinal) 0, &statargc, statargv);
  3744.   firstGC = XCreateGC (Nlm_currentXDisplay,
  3745.                        RootWindow (Nlm_currentXDisplay,
  3746.                                    Nlm_currentXScreen),
  3747.                        0, NULL);
  3748.   Nlm_currentXGC = firstGC;
  3749.   Nlm_SetUpDrawingTools ();
  3750.  
  3751.   Nlm_hScrollBarHeight = 15;
  3752.   Nlm_vScrollBarWidth = 15;
  3753.  
  3754.   Nlm_popupMenuHeight = Nlm_stdLineHeight + 10;
  3755.   Nlm_dialogTextHeight = Nlm_stdLineHeight + 16;
  3756.   
  3757.   arrow = XCreateFontCursor (Nlm_currentXDisplay, XC_top_left_arrow);
  3758.   cross = XCreateFontCursor (Nlm_currentXDisplay, XC_cross);
  3759.   iBeam = XCreateFontCursor (Nlm_currentXDisplay, XC_xterm);
  3760.   plus = XCreateFontCursor (Nlm_currentXDisplay, XC_crosshair);
  3761.   watch = XCreateFontCursor (Nlm_currentXDisplay, XC_watch);
  3762.  
  3763.   currentCursor = arrow;
  3764.   
  3765.   font = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "-*-helvetica-bold-r-*--14-*", TRUE);
  3766.   Nlm_XfontList = XmFontListCreate (font, "dummy");
  3767.  
  3768.   Nlm_fileDialogShell = NULL;
  3769.  
  3770.   return TRUE;
  3771. }
  3772. #endif
  3773.  
  3774. static void Nlm_WindowGo (Nlm_WindoW w)
  3775.  
  3776. {
  3777.   inNotice = FALSE;
  3778.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  3779. }
  3780.  
  3781. static void Nlm_PanelGo (Nlm_PaneL p, Nlm_PoinT pt)
  3782.  
  3783. {
  3784.   Nlm_WindoW  w;
  3785.  
  3786.   inNotice = FALSE;
  3787.   w = Nlm_ParentWindow (p);
  3788.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  3789. }
  3790.  
  3791. static void Nlm_CenterLine (Nlm_RectPtr rptr, Nlm_CharPtr text, Nlm_FonT fnt)
  3792.  
  3793. {
  3794.   if (fnt != NULL) {
  3795.     Nlm_SelectFont (fnt);
  3796.   }
  3797.   rptr->bottom = rptr->top + Nlm_LineHeight ();
  3798.   Nlm_DrawString (rptr, text, 'c', FALSE);
  3799.   rptr->top = rptr->bottom;
  3800. }
  3801.  
  3802. static void Nlm_DrawAbout (Nlm_PaneL p)
  3803.  
  3804. {
  3805.   Nlm_RecT  r;
  3806.  
  3807.   Nlm_ObjectRect (p, &r);
  3808.   Nlm_InsetRect (&r, 4, 4);
  3809.   r.top += 10;
  3810.   Nlm_Blue ();
  3811.   Nlm_CenterLine (&r, "VIBRANT", Nlm_systemFont);
  3812.   r.top += 10;
  3813.   Nlm_Red ();
  3814.   Nlm_CenterLine (&r, "National Center for Biotechnology Information", Nlm_systemFont);
  3815.   r.top += 5;
  3816.   Nlm_CenterLine (&r, "National Library of Medicine", Nlm_systemFont);
  3817.   r.top += 5;
  3818.   Nlm_CenterLine (&r, "National Institutes of Health", Nlm_systemFont);
  3819.   r.top += 10;
  3820.   Nlm_CenterLine (&r, "(301) 496-2475", Nlm_systemFont);
  3821.   r.top += 5;
  3822.   Nlm_CenterLine (&r, "info@ncbi.nlm.nih.gov", Nlm_systemFont);
  3823. }
  3824.  
  3825. static void Nlm_GetSet (void)
  3826.  
  3827. {
  3828.   Nlm_PaneL   p;
  3829.   Nlm_WindoW  w;
  3830.  
  3831.   w = Nlm_ModalWindow (-50, -33, -1, -1, Nlm_WindowGo);
  3832.   p = Nlm_SimplePanel (w, 28 * Nlm_stdCharWidth, 10 * Nlm_stdLineHeight, Nlm_DrawAbout);
  3833.   Nlm_SetPanelClick (p, NULL, NULL, NULL, Nlm_PanelGo);
  3834.   Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  3835.   inNotice = TRUE;
  3836.   while (inNotice) {
  3837.     Nlm_ProcessAnEvent ();
  3838.   }
  3839. }
  3840.  
  3841. static void Nlm_GetReady (void)
  3842.  
  3843. {
  3844. #if defined(WIN_MAC) && (defined(COMP_THINKC) || defined(COMP_CODEWAR))
  3845.   KeyMap  keys;
  3846.  
  3847.   GetKeys (keys);
  3848.   if ((keys [1] & 1) != 0) {
  3849.     Nlm_GetSet ();
  3850.   }
  3851. #endif
  3852. #if defined(COMP_MPW)
  3853.   KeyMap  keys;
  3854.  
  3855.   GetKeys (&keys);
  3856.   if ((keys [1] & 1) != 0) {
  3857.     Nlm_GetSet ();
  3858.   }
  3859. #endif
  3860. #ifdef WIN_MAC
  3861.     /* dgg hack for powerpc */
  3862. #if defined(powerc) || defined(__powerc)
  3863.     strcpy( (Nlm_CharPtr)apName+1, "noname"); apName[0]= 6; 
  3864.     apRefNum= 0;
  3865.     apParam= NULL;
  3866.     {
  3867.     OSErr err;
  3868.     ProcessInfoRec info;
  3869.     ProcessSerialNumber  psn;
  3870.     FSSpec     fileSpec;
  3871.     short        wdref = 0;
  3872.  
  3873.     err= GetCurrentProcess( &psn);
  3874.     if ( err == 0 ) {
  3875.         info.processInfoLength = sizeof(ProcessInfoRec);
  3876.         info.processName = (StringPtr) &apName;
  3877.         info.processAppSpec = &fileSpec;
  3878.         err= GetProcessInformation( &psn, &info);
  3879.         if (err == 0) {
  3880.             /* memcpy( apName, info.processName, info.processName[0]); */
  3881.             apRefNum= fileSpec.vRefNum; 
  3882.  
  3883.             /* !! we need the following for apRefNum */
  3884.             err= OpenWD( fileSpec.vRefNum, fileSpec.parID, 0, &wdref);
  3885.             apRefNum= wdref;
  3886.             /* err= CloseWD( wdref); /* ?? */
  3887.             }
  3888.         }
  3889.     }
  3890.  
  3891. #else
  3892.   GetAppParms (apName, &apRefNum, &apParam);
  3893. #endif
  3894.  /* Nlm_PtoCstr ((Nlm_CharPtr) apName); */
  3895. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  3896.   p2cstr ((StringPtr) apName);
  3897. #endif
  3898. #ifdef COMP_THINKC
  3899.   PtoCstr ((StringPtr) apName);
  3900. #endif
  3901.  
  3902. #endif
  3903. #ifdef WIN_MSWIN
  3904.   if ((GetAsyncKeyState (VK_SHIFT) & 0x8000) != 0) {
  3905.     Nlm_GetSet ();
  3906.   }
  3907. #endif
  3908. #ifdef WIN_MOTIF
  3909.   argc = statargc;
  3910.   argv = statargv;
  3911. #endif
  3912.   Nlm_ArrowCursor ();
  3913. }
  3914.  
  3915. static void Nlm_CleanUpWindows (void)
  3916.  
  3917. /*
  3918. *  Since submenus goes into the Macintosh desktop menu bar, to allow for
  3919. *  command key equivalents, it can be very dangerous to remove the menu
  3920. *  bar.  The submenu linked into the menu bar now no longer removes its
  3921. *  children, leaving that up to the submenu item.
  3922. */
  3923.  
  3924. {
  3925.   Nlm_GraphiC  g;
  3926.   Nlm_MenuBaR  mb;
  3927.   Nlm_GraphiC  n;
  3928.   Nlm_WindoW   w;
  3929.  
  3930. #ifdef WIN_MSWIN
  3931.   if (timerID != 0) {
  3932.     KillTimer (NULL, timerID);
  3933.   }
  3934. #endif
  3935. #ifdef WIN_MOTIF
  3936.   XtRemoveTimeOut (windowTimer);
  3937. #endif
  3938.   w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  3939.   while (w != NULL && w != Nlm_systemWindow) {
  3940.     Nlm_UseWindow (w);
  3941.     Nlm_DoHide ((Nlm_GraphiC) w, TRUE, FALSE);
  3942.     mb = Nlm_GetWindowMenuBar (w);
  3943.     if (mb != NULL) {
  3944.       Nlm_DoRemove ((Nlm_GraphiC) mb, FALSE);
  3945.     }
  3946.     g = Nlm_GetChild ((Nlm_GraphiC) w);
  3947.     while (g != NULL) {
  3948.       n = Nlm_GetNext (g);
  3949.       Nlm_DoRemove (g, FALSE);
  3950.       g = n;
  3951.     }
  3952.     w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  3953.   }
  3954.   w = Nlm_desktopWindow;
  3955.   mb = Nlm_GetWindowMenuBar (w);
  3956.   if (mb != NULL) {
  3957.     Nlm_DoRemove ((Nlm_GraphiC) mb, FALSE);
  3958.     Nlm_SetWindowMenuBar (w, NULL);
  3959.   }
  3960. }
  3961.  
  3962. #ifdef WIN_MAC
  3963. main ()
  3964.  
  3965. {
  3966.   Nlm_Int2  i;
  3967.  
  3968.   MaxApplZone ();
  3969.   for (i = 0; i < 20; i++) {
  3970.     MoreMasters ();
  3971.   }
  3972.   InitGraf (&qd.thePort);
  3973.   InitFonts ();
  3974.   FlushEvents (everyEvent, 0);
  3975.   InitWindows ();
  3976.   InitMenus ();
  3977.   TEInit ();
  3978.   InitDialogs (0);
  3979.   InitCursor ();
  3980.  
  3981.   Nlm_InitVibrantHooks ();
  3982.  
  3983.   Nlm_InitWindows ();
  3984.   Nlm_InitBars ();
  3985.   Nlm_InitButtons ();
  3986.   Nlm_InitExtras ();
  3987.   Nlm_InitGroup ();
  3988.   Nlm_InitLists ();
  3989.   Nlm_InitMenus ();
  3990.   Nlm_InitPrompt ();
  3991.   Nlm_InitSlate ();
  3992.   Nlm_InitTexts ();
  3993.   Nlm_SetupWindows ();
  3994.   Nlm_RegisterWindows ();
  3995.   Nlm_RegisterTexts ();
  3996.   Nlm_RegisterSlates ();
  3997.   Nlm_GetReady ();
  3998.  
  3999.   Nlm_Main ();
  4000.  
  4001. #ifndef DCLAP
  4002.     /* dgg -- speed up quit; all this cleanup isn't needed */
  4003.   Nlm_CleanUpWindows ();
  4004.   Nlm_CleanUpDrawingTools ();
  4005.   Nlm_FreeWindows ();
  4006.   Nlm_FreeBars ();
  4007.   Nlm_FreeButtons ();
  4008.   Nlm_FreeExtras ();
  4009.   Nlm_FreeGroup ();
  4010.   Nlm_FreeLists ();
  4011.   Nlm_FreeMenus ();
  4012.   Nlm_FreePrompt ();
  4013.   Nlm_FreeSlate ();
  4014.   Nlm_FreeTexts ();
  4015.   Nlm_FreeConfigStruct ();
  4016. #endif
  4017.   ExitToShell ();
  4018.     return 0;
  4019. }
  4020. #endif
  4021.  
  4022. #ifdef WIN_MSWIN
  4023. #ifdef WIN32
  4024. static int Nlm_HandleException (DWORD code)
  4025.  
  4026. {
  4027.   Nlm_Message (MSG_OK, "WIN32 exception %ld", (long) code);
  4028.   return EXCEPTION_CONTINUE_EXECUTION;
  4029. }
  4030. #endif
  4031.  
  4032. int CALLBACK WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  4033.                       LPSTR lpszCmdLine, int nCmdShow)
  4034.  
  4035. {
  4036.   Nlm_Char  str [32];
  4037.   WNDCLASS  wc;
  4038.  
  4039. #ifdef WIN32
  4040.   try {
  4041. #endif
  4042.  
  4043.   Nlm_currentHInst = hInstance;
  4044.  
  4045.   Nlm_InitVibrantHooks ();
  4046.  
  4047.   Nlm_InitWindows ();
  4048.   Nlm_InitBars ();
  4049.   Nlm_InitButtons ();
  4050.   Nlm_InitExtras ();
  4051.   Nlm_InitGroup ();
  4052.   Nlm_InitLists ();
  4053.   Nlm_InitMenus ();
  4054.   Nlm_InitPrompt ();
  4055.   Nlm_InitSlate ();
  4056.   Nlm_InitTexts ();
  4057.   Nlm_SetupWindows ();
  4058.   if (! (Nlm_RegisterWindows ())) {
  4059.     return FALSE;
  4060.   }
  4061.   if (! (Nlm_RegisterTexts ())) {
  4062.     return FALSE;
  4063.   }
  4064.   if (! (Nlm_RegisterSlates ())) {
  4065.     sprintf (str, "Nlm_WindowClass%ld", (long) (int) Nlm_currentHInst);
  4066.     UnregisterClass (str, Nlm_currentHInst);
  4067.     return FALSE;
  4068.   }
  4069.   Nlm_GetReady ();
  4070.  
  4071.   Nlm_Main ();
  4072.  
  4073.   Nlm_CleanUpWindows ();
  4074.   Nlm_CleanUpDrawingTools ();
  4075.   Nlm_FreeWindows ();
  4076.   Nlm_FreeBars ();
  4077.   Nlm_FreeButtons ();
  4078.   Nlm_FreeExtras ();
  4079.   Nlm_FreeGroup ();
  4080.   Nlm_FreeLists ();
  4081.   Nlm_FreeMenus ();
  4082.   Nlm_FreePrompt ();
  4083.   Nlm_FreeSlate ();
  4084.   Nlm_FreeTexts ();
  4085.   Nlm_FreeConfigStruct ();
  4086.  
  4087.   sprintf (str, "Nlm_WindowClass%ld", (long) (int) Nlm_currentHInst);
  4088.   if (GetClassInfo (Nlm_currentHInst, str, &wc)) {
  4089.     DeleteObject (wc.hbrBackground);
  4090.   }
  4091.   UnregisterClass (str, Nlm_currentHInst);
  4092.   sprintf (str, "Nlm_SlateClass%ld", (long) (int) Nlm_currentHInst);
  4093.   UnregisterClass (str, Nlm_currentHInst);
  4094.  
  4095. #ifdef WIN32
  4096.   } except (Nlm_HandleException (GetExceptionCode ())) {
  4097.   }
  4098. #endif
  4099.  
  4100.   return TRUE;
  4101. }
  4102. #endif
  4103.  
  4104. #ifdef WIN_MOTIF
  4105. main (int argc, char *argv [])
  4106.  
  4107. {
  4108.   Nlm_Int2  retval;
  4109.  
  4110.   statargc = argc;
  4111.   statargv = argv;
  4112.  
  4113.   Nlm_InitVibrantHooks ();
  4114.  
  4115.   Nlm_InitWindows ();
  4116.   Nlm_InitButtons ();
  4117.   Nlm_InitExtras ();
  4118.   Nlm_InitGroup ();
  4119.   Nlm_InitBars ();
  4120.   Nlm_InitLists ();
  4121.   Nlm_InitMenus ();
  4122.   Nlm_InitPrompt ();
  4123.   Nlm_InitSlate ();
  4124.   Nlm_InitTexts ();
  4125.   if (! Nlm_SetupWindows ()) {
  4126.     return FALSE;
  4127.   }
  4128.   Nlm_RegisterWindows ();
  4129.   Nlm_RegisterTexts ();
  4130.   Nlm_RegisterSlates ();
  4131.  
  4132.   Nlm_GetReady ();
  4133.   retval = Nlm_Main ();
  4134.  
  4135.   Nlm_CleanUpWindows ();
  4136.   Nlm_CleanUpDrawingTools ();
  4137.   Nlm_FreeWindows ();
  4138.   Nlm_FreeBars ();
  4139.   Nlm_FreeButtons ();
  4140.   Nlm_FreeExtras ();
  4141.   Nlm_FreeGroup ();
  4142.   Nlm_FreeLists ();
  4143.   Nlm_FreeMenus ();
  4144.   Nlm_FreePrompt ();
  4145.   Nlm_FreeSlate ();
  4146.   Nlm_FreeTexts ();
  4147.   Nlm_FreeConfigStruct ();
  4148.   Nlm_currentWindowTool = NULL;
  4149.   Nlm_currentXWindow = 0;
  4150.   Nlm_currentXGC = NULL;
  4151.   if (Nlm_currentXDisplay != NULL) {
  4152.     if (Nlm_fileDialogShell != NULL) {
  4153.       XtDestroyWidget (Nlm_fileDialogShell);
  4154.     }
  4155.     if (Nlm_XfontList != NULL) {
  4156.       XmFontListFree (Nlm_XfontList);
  4157.     }
  4158.     XFreeCursor (Nlm_currentXDisplay, arrow);
  4159.     XFreeCursor (Nlm_currentXDisplay, cross);
  4160.     XFreeCursor (Nlm_currentXDisplay, iBeam);
  4161.     XFreeCursor (Nlm_currentXDisplay, plus);
  4162.     XFreeCursor (Nlm_currentXDisplay, watch);
  4163.     XFreeGC (Nlm_currentXDisplay, firstGC);
  4164.     XCloseDisplay (Nlm_currentXDisplay);
  4165.   }
  4166.   exit (retval);
  4167. }
  4168. #endif
  4169.  
  4170. extern void Nlm_Metronome (Nlm_VoidProc actn)
  4171.  
  4172. {
  4173.   timerAction = actn;
  4174. }
  4175.  
  4176. extern void Nlm_RemoveDyingWindows (void)
  4177.  
  4178. /*
  4179. *  Since submenus goes into the Macintosh desktop menu bar, to allow for
  4180. *  command key equivalents, it can be very dangerous to remove the menu
  4181. *  bar.  The submenu linked into the menu bar now no longer removes its
  4182. *  children, leaving that up to the submenu item.
  4183. */
  4184.  
  4185. {
  4186.   Nlm_GraphiC     g;
  4187.   Nlm_MenuBaR     mb;
  4188.   Nlm_GraphiC     n;
  4189.   Nlm_PortTool    tempPort;
  4190.   Nlm_WindoW      w;
  4191.   Nlm_WindowData  wdata;
  4192.   Nlm_WindowTool  wptr;
  4193. #ifdef WIN_MAC
  4194.   PenState        state;
  4195. #endif
  4196. #ifdef WIN_MOTIF
  4197.   Nlm_ShellTool   shl;
  4198. #endif
  4199.  
  4200.   while (dyingWindow != NULL) {
  4201.     w = dyingWindow;
  4202.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  4203.     Nlm_currentWindowTool = wptr;
  4204. #ifdef WIN_MAC
  4205.     GetPort (&tempPort);
  4206.     GetPenState (&state);
  4207.     SetPort (wptr);
  4208.     Nlm_currentWindowTool = wptr;
  4209.     Nlm_SetUpdateRegion (wptr);
  4210. #endif
  4211. #ifdef WIN_MSWIN
  4212.     tempPort = Nlm_currentHDC;
  4213.     Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) w);
  4214. #endif
  4215. #ifdef WIN_MOTIF
  4216.     XSync (Nlm_currentXDisplay, FALSE);
  4217.     Nlm_currentXGC = Nlm_ParentWindowPort ((Nlm_GraphiC) w);
  4218. #endif
  4219.     mb = Nlm_GetWindowMenuBar (w);
  4220.     if (mb != NULL) {
  4221.       Nlm_DoRemove ((Nlm_GraphiC) mb, FALSE);
  4222.       Nlm_SetWindowMenuBar (w, NULL);
  4223.     }
  4224.     g = Nlm_GetChild ((Nlm_GraphiC) w);
  4225.     while (g != NULL) {
  4226.       n = Nlm_GetNext (g);
  4227.       Nlm_DoRemove (g, FALSE);
  4228.       g = n;
  4229.     }
  4230.     Nlm_ResetDrawingTools ();
  4231.     Nlm_GetWindowData (w, &wdata);
  4232.     if (wdata.data != NULL && wdata.cleanup != NULL) {
  4233.       wdata.cleanup (w, wdata.data);
  4234.     }
  4235. #ifdef WIN_MAC
  4236.     SetPort (tempPort);
  4237.     Nlm_currentWindowTool = tempPort;
  4238.     Nlm_SetUpdateRegion (tempPort);
  4239.     SetPenState (&state);
  4240.     CloseWindow (wptr);
  4241.     Nlm_MemFree (wptr);
  4242. #endif
  4243. #ifdef WIN_MSWIN
  4244.     Nlm_currentHDC = tempPort;
  4245.     RemoveProp (wptr, (LPSTR) "Nlm_VibrantProp");
  4246.     DestroyWindow (wptr);
  4247. #endif
  4248. #ifdef WIN_MOTIF
  4249.     if (wdata.title != NULL) {
  4250.       Nlm_MemFree (wdata.title);
  4251.     }
  4252.     Nlm_currentWindowTool = NULL;
  4253.     Nlm_currentXWindow = 0;
  4254.     Nlm_currentXGC = firstGC;
  4255.     shl = Nlm_GetWindowShell (w);
  4256.     if (NLM_QUIET) {
  4257.       if (Nlm_WindowHasBeenShown (w)) {
  4258.         XtDestroyWidget (shl);
  4259.       }
  4260.     } else {
  4261.       XtDestroyWidget (shl);
  4262.     }
  4263.     XSync (Nlm_currentXDisplay, FALSE);
  4264. #endif
  4265.     dyingWindow = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  4266.     Nlm_HandFree (w);
  4267.     recentWindow = NULL;
  4268.     Nlm_Update ();
  4269.   }
  4270. }
  4271.  
  4272. extern void Nlm_Update (void)
  4273.  
  4274. {
  4275. #ifdef WIN_MAC
  4276.   while (EventAvail (updateMask, &Nlm_currentEvent)) {
  4277.     if (WaitNextEvent (updateMask, &Nlm_currentEvent, 0, NULL)) {
  4278.       Nlm_HandleEvent ();
  4279.     }
  4280.   }
  4281. #endif
  4282. #ifdef WIN_MSWIN
  4283.   while (PeekMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT, PM_NOREMOVE)) {
  4284.     if (GetMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT)) {
  4285.       if (Nlm_VibrantDisabled ()) {
  4286.         discard_count++; /* really just a place to set a breakpoint */
  4287.       }
  4288.       TranslateMessage (&Nlm_currentMssg);
  4289.       DispatchMessage (&Nlm_currentMssg);
  4290.     }
  4291.   }
  4292. #endif
  4293. #ifdef WIN_MOTIF
  4294.   XEvent       event;
  4295.   XtInputMask  mask;
  4296.  
  4297.   XSync (Nlm_currentXDisplay, FALSE);
  4298.   mask = XtAppPending (Nlm_appContext);
  4299.   if (mask != 0) {
  4300.     while (XCheckTypedEvent (Nlm_currentXDisplay, Expose, &event)) {
  4301.       XtDispatchEvent (&event);
  4302.     }
  4303.   }
  4304.   XSync (Nlm_currentXDisplay, FALSE);
  4305. #endif
  4306. }
  4307.  
  4308. extern void Nlm_KeyboardView (Nlm_KeyProc key)
  4309.  
  4310. {
  4311.   keyAction = key;
  4312. }
  4313.  
  4314. #ifdef WIN_MSWIN
  4315. static void Nlm_ProcessKeyPress (LPMSG lpMsg)
  4316.  
  4317. {
  4318.   Nlm_Char  ch;
  4319.  
  4320.   if (lpMsg->message == WM_CHAR) {
  4321.     ch = (Nlm_Char) lpMsg->wParam;
  4322.     if (keyAction != NULL) {
  4323.       keyAction (ch);
  4324.     }
  4325.   }
  4326. }
  4327. #endif
  4328.  
  4329. #ifdef WIN_MOTIF
  4330. static void Nlm_ProcessKeyPress (XEvent *event)
  4331.  
  4332. {
  4333.   Nlm_Char        buffer [20];
  4334.   Nlm_Char        ch;
  4335.   int             charcount;
  4336.   XComposeStatus  compose;
  4337.   KeySym          keysym;
  4338.  
  4339.   if (event->type == KeyPress) {
  4340.     buffer [0] = '\0';
  4341.     charcount = XLookupString (&(event->xkey), buffer, 20, &keysym, &compose);
  4342.     if (charcount >= 0 && charcount < 20) {
  4343.       buffer [charcount] = '\0';
  4344.     }
  4345.     if (keyAction != NULL) {
  4346.       ch = buffer [0];
  4347.       keyAction (ch);
  4348.     }
  4349.   }
  4350. }
  4351. #endif
  4352.  
  4353. extern void Nlm_ProcessAnEvent (void)
  4354.  
  4355. {
  4356. #ifdef WIN_MAC
  4357.   if (EventAvail (everyEvent, &Nlm_currentEvent)) {
  4358.     if (WaitNextEvent (everyEvent, &Nlm_currentEvent, 0, NULL)) {
  4359.       Nlm_HandleEvent ();
  4360.     }
  4361.   }
  4362. #endif
  4363. #ifdef WIN_MSWIN
  4364.   if (PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_NOREMOVE)) {
  4365.     if (GetMessage (&Nlm_currentMssg, NULL, 0, 0)) {
  4366. #if  defined(DCLAP) && !defined(WIN16) 
  4367.         if (!(Nlm_hAccel 
  4368.       && TranslateAccelerator( Nlm_menuHwnd, Nlm_hAccel, &Nlm_currentMssg)))  
  4369. #endif
  4370.             {
  4371.       TranslateMessage (&Nlm_currentMssg);
  4372.       Nlm_ProcessKeyPress (&Nlm_currentMssg);
  4373.       DispatchMessage (&Nlm_currentMssg);
  4374.             }
  4375.     }
  4376.   }
  4377. #endif
  4378. #ifdef WIN_MOTIF
  4379.   XEvent       event;
  4380.   XtInputMask  mask;
  4381.  
  4382.   mask = XtAppPending (Nlm_appContext);
  4383.   if (mask != 0) {
  4384.     XtAppNextEvent (Nlm_appContext, &event);
  4385.     Nlm_ProcessKeyPress (&event);
  4386.     XtDispatchEvent (&event);
  4387.   }
  4388. #endif
  4389. }
  4390.  
  4391. extern void Nlm_ProcessTimerEvent (void)
  4392.  
  4393. {
  4394. #ifdef WIN_MAC
  4395.   Nlm_Int4  delta;
  4396.   Nlm_Int4  ticks;
  4397.  
  4398.   ticks = Nlm_ComputerTime ();
  4399.   delta = ticks - lastTimerTime;
  4400.   if (delta >= 3) {
  4401.     lastTimerTime = ticks;
  4402.     if (timerAction != NULL) {
  4403.       timerAction ();
  4404.     }
  4405.   }
  4406. #endif
  4407. }
  4408.  
  4409. #ifdef WIN_MAC
  4410. static void Nlm_ProcessIdle (void)
  4411.  
  4412. {
  4413.   Nlm_PointTool  ptool;
  4414.  
  4415.   Nlm_ProcessTimerEvent ();
  4416.   GetMouse (&ptool);
  4417.   LocalToGlobal (&ptool);
  4418.   Nlm_PointToolToPoinT (ptool, &Nlm_globalMouse);
  4419.   frontWindow = Nlm_FindWindowRec (FrontWindow ());
  4420.   Nlm_DoIdle ((Nlm_GraphiC) frontWindow, Nlm_globalMouse);
  4421.   Nlm_ClearKeys ();
  4422. }
  4423. #endif
  4424.  
  4425. extern void Nlm_ProcessEventOrIdle (void)
  4426.  
  4427. {
  4428. #ifdef WIN_MAC
  4429.   if (EventAvail (everyEvent, &Nlm_currentEvent)) {
  4430.     if (WaitNextEvent (everyEvent, &Nlm_currentEvent, 0, NULL)) {
  4431.       Nlm_HandleEvent ();
  4432.     }
  4433.   } else {
  4434.     Nlm_ProcessIdle ();
  4435.   }
  4436. #endif
  4437. #ifdef WIN_MSWIN
  4438.   if (PeekMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT, PM_NOREMOVE)) {
  4439.     if (GetMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT)) {
  4440.       TranslateMessage (&Nlm_currentMssg);
  4441.       DispatchMessage (&Nlm_currentMssg);
  4442.     }
  4443.   } else if (PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_NOREMOVE)) {
  4444.     if (GetMessage (&Nlm_currentMssg, NULL, 0, 0)) {
  4445. #if  defined(DCLAP) && !defined(WIN16) 
  4446.     /* if (!(Nlm_hAccel */
  4447.     if (!(TranslateAccelerator( Nlm_menuHwnd, Nlm_hAccel, &Nlm_currentMssg)))      {
  4448. #endif
  4449.             {
  4450.       TranslateMessage (&Nlm_currentMssg);
  4451.       Nlm_ProcessKeyPress (&Nlm_currentMssg);
  4452.       DispatchMessage (&Nlm_currentMssg);
  4453.             }
  4454.     }
  4455.   }
  4456. #endif
  4457. #ifdef WIN_MOTIF
  4458.   XEvent       event;
  4459.   XtInputMask  mask;
  4460.  
  4461.   mask = XtAppPending (Nlm_appContext);
  4462.   if (mask != 0) {
  4463.     if (XCheckTypedEvent (Nlm_currentXDisplay, Expose, &event)) {
  4464.       XtDispatchEvent (&event);
  4465.     } else {
  4466.       XtAppNextEvent (Nlm_appContext, &event);
  4467.       Nlm_ProcessKeyPress (&event);
  4468.       XtDispatchEvent (&event);
  4469.     }
  4470.   }
  4471. #endif
  4472. }
  4473.  
  4474.  
  4475.  
  4476. extern void Nlm_ProcessExternalEvent (void)
  4477.  
  4478. {
  4479. #ifdef WIN_MAC
  4480.   if (WaitNextEvent (everyEvent, &Nlm_currentEvent, 10, NULL)) {
  4481.     Nlm_HandleEvent ();
  4482.   }
  4483. #endif
  4484. #ifdef WIN_MSWIN
  4485.   if (PeekMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT, PM_NOREMOVE)) {
  4486.     if (GetMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT)) {
  4487.       TranslateMessage (&Nlm_currentMssg);
  4488.       DispatchMessage (&Nlm_currentMssg);
  4489.     }
  4490.   } else if (PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_NOREMOVE)) {
  4491.     if (GetMessage (&Nlm_currentMssg, NULL, 0, 0)) {
  4492. #if  defined(DCLAP) && !defined(WIN16) 
  4493.         if (!(Nlm_hAccel 
  4494.       && TranslateAccelerator( Nlm_menuHwnd, Nlm_hAccel, &Nlm_currentMssg))) 
  4495. #endif
  4496.             {
  4497.       TranslateMessage (&Nlm_currentMssg);
  4498.       Nlm_ProcessKeyPress (&Nlm_currentMssg);
  4499.       DispatchMessage (&Nlm_currentMssg);
  4500.             }
  4501.     }
  4502.   }
  4503. #endif
  4504. #ifdef WIN_MOTIF
  4505.   XEvent       event;
  4506.   XtInputMask  mask;
  4507.  
  4508.   mask = XtAppPending (Nlm_appContext);
  4509.   if (mask != 0) {
  4510.     if (XCheckTypedEvent (Nlm_currentXDisplay, Expose, &event)) {
  4511.       XtDispatchEvent (&event);
  4512.     } else {
  4513.       XtAppNextEvent (Nlm_appContext, &event);
  4514.       Nlm_ProcessKeyPress (&event);
  4515.       XtDispatchEvent (&event);
  4516.     }
  4517.   }
  4518. #endif
  4519. }
  4520.  
  4521. extern void Nlm_ProcessEvents (void)
  4522.  
  4523. {
  4524. #ifdef WIN_MAC
  4525.   while (! quitProgram) {
  4526.     if (! EventAvail (everyEvent, &Nlm_currentEvent)) {
  4527.       Nlm_ProcessIdle ();
  4528.     }
  4529.     while (WaitNextEvent (everyEvent, &Nlm_currentEvent, 1, NULL)) {
  4530.       Nlm_HandleEvent ();
  4531.       Nlm_RemoveDyingWindows ();
  4532.     }
  4533.   }
  4534. #endif
  4535. #ifdef WIN_MSWIN
  4536.   while (! quitProgram) {
  4537.     while (PeekMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT, PM_NOREMOVE)) {
  4538.       if (GetMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT)) {
  4539.         TranslateMessage (&Nlm_currentMssg);
  4540.         DispatchMessage (&Nlm_currentMssg);
  4541.       }
  4542.     }
  4543.     if (GetMessage (&Nlm_currentMssg, NULL, 0, 0)) {
  4544. #if  defined(DCLAP) && !defined(WIN16) 
  4545.         if (!(Nlm_hAccel 
  4546.       && TranslateAccelerator( Nlm_menuHwnd, Nlm_hAccel, &Nlm_currentMssg)))
  4547. #endif
  4548.            {
  4549.       TranslateMessage (&Nlm_currentMssg);
  4550.       Nlm_ProcessKeyPress (&Nlm_currentMssg);
  4551.       DispatchMessage (&Nlm_currentMssg);
  4552.       Nlm_RemoveDyingWindows ();
  4553.             }
  4554.     }
  4555.   }
  4556. #endif
  4557. #ifdef WIN_MOTIF
  4558.   XEvent       event;
  4559.   XtInputMask  mask;
  4560.  
  4561.   while (! quitProgram) {
  4562.     mask = XtAppPending (Nlm_appContext);
  4563.     if (mask != 0) {
  4564.       while (XCheckTypedEvent (Nlm_currentXDisplay, Expose, &event)) {
  4565.         XtDispatchEvent (&event);
  4566.       }
  4567.     }
  4568.     XtAppNextEvent (Nlm_appContext, &event);
  4569.     Nlm_ProcessKeyPress (&event);
  4570.     XtDispatchEvent (&event);
  4571.     Nlm_RemoveDyingWindows ();
  4572.   }
  4573.   if (Nlm_currentXDisplay != NULL) {
  4574.     XSync (Nlm_currentXDisplay, TRUE);
  4575.   }
  4576. #endif
  4577.   Nlm_RemoveDyingWindows ();
  4578. }
  4579.  
  4580. extern Nlm_Boolean Nlm_EventAvail (void)
  4581.  
  4582. {
  4583. #ifdef WIN_MAC
  4584.   return (EventAvail (everyEvent, &Nlm_currentEvent));
  4585. #endif
  4586. #ifdef WIN_MSWIN
  4587.   return (Nlm_Boolean) (PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_NOREMOVE | PM_NOYIELD));
  4588. #endif
  4589. #ifdef WIN_MOTIF
  4590.   return (XtAppPending (Nlm_appContext) != 0);
  4591. #endif
  4592. }
  4593.  
  4594. extern void Nlm_FlushEvents (void)
  4595.  
  4596. {
  4597. #ifdef WIN_MAC
  4598.   FlushEvents (everyEvent - updateMask, 0);
  4599. #endif
  4600. #ifdef WIN_MSWIN
  4601.   Nlm_Boolean  goOn;
  4602.  
  4603.   goOn = TRUE;
  4604.   while (goOn) {
  4605.     goOn = (Nlm_Boolean) PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_REMOVE | PM_NOYIELD);
  4606.     if (goOn && Nlm_currentMssg.message == WM_PAINT) {
  4607.       goOn = FALSE;
  4608.     }
  4609.   }
  4610. #endif
  4611. #ifdef WIN_MOTIF
  4612.   if (Nlm_currentXDisplay != NULL) {
  4613.     XSync (Nlm_currentXDisplay, FALSE);
  4614.   }
  4615. #endif
  4616. }
  4617.  
  4618. extern void Nlm_QuitProgram (void)
  4619.  
  4620. {
  4621.   quitProgram = TRUE;
  4622. #ifdef WIN_MSWIN
  4623.   PostQuitMessage (0);
  4624. #endif
  4625. }
  4626.  
  4627. extern void Nlm_UnloadSegment (Nlm_VoidProc routineAddr)
  4628.  
  4629. {
  4630. #ifdef WIN_MAC
  4631.   if (routineAddr != NULL) {
  4632.     UnloadSeg ((void *) routineAddr);
  4633.   }
  4634. #endif
  4635. }
  4636.  
  4637. static void Nlm_GetArgsOkProc (Nlm_ButtoN b)
  4638.  
  4639. {
  4640.   getArgsBoxUp = FALSE;
  4641.   getArgsOk = TRUE;
  4642. }
  4643.  
  4644. static void Nlm_GetArgsCancelProc (Nlm_ButtoN b)
  4645.  
  4646. {
  4647.   getArgsBoxUp = FALSE;
  4648. }
  4649.  
  4650. static Nlm_GraphiC Nlm_GetPrevObject (Nlm_GraphiC g)
  4651.  
  4652. {
  4653.   Nlm_GraphiC  prev;
  4654.   Nlm_GraphiC  prnt;
  4655.   Nlm_GraphiC  thisitem;
  4656.  
  4657.   prev = NULL;
  4658.   if (g != NULL) {
  4659.     prnt = Nlm_GetParent (g);
  4660.     thisitem = Nlm_GetChild (prnt);
  4661.     while (thisitem != NULL && thisitem != g) {
  4662.       prev = thisitem;
  4663.       thisitem = Nlm_GetNext (thisitem);
  4664.     }
  4665.   }
  4666.   return prev;
  4667. }
  4668.  
  4669. static void Nlm_GetArgsFileInProc (Nlm_ButtoN b)
  4670.  
  4671. {
  4672.   Nlm_Char  path [PATH_MAX];
  4673.   Nlm_TexT  t;
  4674.  
  4675.   t = (Nlm_TexT) Nlm_GetPrevObject ((Nlm_GraphiC) b);
  4676.   if (t != NULL) {
  4677.     if (Nlm_GetInputFileName (path, sizeof (path), "", "TEXT")) {
  4678.       Nlm_SetTitle ((Nlm_Handle) t, path);
  4679.     }
  4680.   }
  4681. }
  4682.  
  4683. static void Nlm_GetArgsFileOutProc (Nlm_ButtoN b)
  4684.  
  4685. {
  4686.   Nlm_Char  path [PATH_MAX];
  4687.   Nlm_TexT  t;
  4688.  
  4689.   t = (Nlm_TexT) Nlm_GetPrevObject ((Nlm_GraphiC) b);
  4690.   if (t != NULL) {
  4691.     if (Nlm_GetOutputFileName (path, sizeof (path), "")) {
  4692.       Nlm_SetTitle ((Nlm_Handle) t, path);
  4693.     }
  4694.   }
  4695. }
  4696.  
  4697. #define MAX_ARGS 50
  4698.  
  4699. typedef Nlm_Handle PNTR Nlm_HandlePtr;
  4700.  
  4701. extern Nlm_Boolean Nlm_GetArgs (Nlm_CharPtr progname, Nlm_Int2 numargs, Nlm_ArgPtr ap)
  4702.  
  4703. {
  4704.   static char * TypeStrings[9] = {
  4705.         "",
  4706.         "Integer: ",
  4707.         "Float: ",
  4708.         "String: ",
  4709.         "File In: ",
  4710.         "File Out: ",
  4711.         "Data In: ",
  4712.         "Data Out: " };
  4713.   Nlm_Boolean    okay = FALSE;
  4714.   Nlm_Boolean    range;
  4715.   Nlm_Int2       i;
  4716.   Nlm_Int2       j;
  4717.   Nlm_Int4       ifrom, ito;
  4718.   Nlm_FloatHi    ffrom, fto;
  4719.   Nlm_ArgPtr     curarg;
  4720.   Nlm_Boolean    resolved [MAX_ARGS];
  4721.   Nlm_Char       arg [80];
  4722.   Nlm_CharPtr    buf;
  4723.   Nlm_Char       ch;
  4724.   Nlm_Int2       delta;
  4725.   Nlm_GrouP      g;
  4726.   Nlm_GrouP      h;
  4727.   Nlm_HandlePtr  hp;
  4728.   Nlm_Int2       k;
  4729.   Nlm_Int2       l;
  4730.   Nlm_GrouP      pg;
  4731.   Nlm_RecT       r1;
  4732.   Nlm_RecT       r2;
  4733.   Nlm_Boolean    smallScreen;
  4734.   Nlm_WindoW     w;
  4735.   Nlm_TexT       firstText;
  4736.   Nlm_CharPtr    tmp;
  4737.  
  4738.   if ((ap == NULL) || (numargs == 0) || (numargs > MAX_ARGS)) {
  4739.     return okay;
  4740.   }
  4741.  
  4742.   curarg = ap;
  4743.   Nlm_MemFill (resolved, '\0', (MAX_ARGS * sizeof(Nlm_Boolean)));
  4744.  
  4745.   for (i = 0; i < numargs; i++, curarg++) {
  4746.     if ((curarg->type < ARG_BOOLEAN) || (curarg->type > ARG_DATA_OUT)) {
  4747.       Message(MSG_ERROR, "Invalid Arg->type in %s", curarg->prompt);
  4748.       return okay;
  4749.     }
  4750.     curarg->intvalue = 0;
  4751.     curarg->floatvalue = 0.0;
  4752.     curarg->strvalue = NULL;
  4753.     if (curarg->defaultvalue != NULL) {
  4754.       resolved [i] = TRUE;
  4755.       switch (curarg->type) {
  4756.         case ARG_BOOLEAN:
  4757.           if (TO_UPPER(*curarg->defaultvalue) == 'T') {
  4758.             curarg->intvalue = 1;
  4759.           } else {
  4760.             curarg->intvalue = 0;
  4761.           }
  4762.           break;
  4763.         case ARG_INT:
  4764.           sscanf(curarg->defaultvalue, "%ld", &curarg->intvalue);
  4765.           break;
  4766.         case ARG_FLOAT:
  4767.           sscanf(curarg->defaultvalue, "%lf", &curarg->floatvalue);
  4768.           break;
  4769.         case ARG_STRING:
  4770.         case ARG_FILE_IN:
  4771.         case ARG_FILE_OUT:
  4772.         case ARG_DATA_IN:
  4773.         case ARG_DATA_OUT:
  4774.           curarg->strvalue = StringSave (curarg->defaultvalue);
  4775.           break;
  4776.       }
  4777.     }
  4778.   }
  4779.  
  4780.   Nlm_StringMove(arg, progname);
  4781.   w = Nlm_FixedWindow (-50, -33, -10, -10, arg, NULL);
  4782.   smallScreen = FALSE;
  4783. #ifdef WIN_MAC
  4784.   if (Nlm_screenRect.right < 513 || Nlm_screenRect.bottom < 343) {
  4785.     smallScreen = TRUE;
  4786.   }
  4787. #endif
  4788. #ifdef WIN_MSWIN
  4789.   if (Nlm_screenRect.bottom < 352) {
  4790.     smallScreen = TRUE;
  4791.   }
  4792. #endif
  4793.   g = Nlm_HiddenGroup (w, 4, 0, NULL);
  4794.   hp = (Nlm_HandlePtr) Nlm_MemNew (numargs * sizeof (Nlm_Handle));
  4795.  
  4796.   firstText = NULL;
  4797.   curarg = ap;
  4798.   for (i = 0, j = 0; i < numargs; i++, j++, curarg++) {
  4799.     if ((smallScreen && j >= 10) || j >= 15) {
  4800.       j = 0;
  4801.       Nlm_Advance (w);
  4802.       g = Nlm_HiddenGroup (w, 4, 0, NULL);
  4803.     }
  4804.     Nlm_StaticPrompt (g, TypeStrings[curarg->type - 1], 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4805.     switch (curarg->type) {
  4806.       case ARG_BOOLEAN:
  4807.         hp [i] = (Nlm_Handle) Nlm_CheckBox (g, curarg->prompt, NULL);
  4808.         Nlm_StaticPrompt (g, "", 0, 0, Nlm_systemFont, 'l');
  4809.         if (curarg->intvalue == 1) {
  4810.           Nlm_SetStatus (hp [i], TRUE);
  4811.         }
  4812.         break;
  4813.       case ARG_INT:
  4814.         Nlm_StaticPrompt (g, curarg->prompt, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4815.         hp [i] = (Nlm_Handle) Nlm_DialogText (g, curarg->defaultvalue, 10, NULL);
  4816.         if (firstText == NULL) {
  4817.           firstText = (Nlm_TexT) hp [i];
  4818.         }
  4819.         break;
  4820.       case ARG_FLOAT:
  4821.         Nlm_StaticPrompt (g, curarg->prompt, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4822.         hp [i] = (Nlm_Handle) Nlm_DialogText (g, curarg->defaultvalue, 10, NULL);
  4823.         if (firstText == NULL) {
  4824.           firstText = (Nlm_TexT) hp [i];
  4825.         }
  4826.         break;
  4827.       case ARG_STRING:
  4828.         pg = Nlm_HiddenGroup (g, 0, 10, NULL);
  4829.         Nlm_SetGroupMargins (pg, 1, 1);
  4830.         Nlm_SetGroupSpacing (pg, 1, 1);
  4831.         buf = curarg->prompt;
  4832.         k = 0;
  4833.         while (Nlm_StringLen (buf + k) > 0) {
  4834.           l = 0;
  4835.           ch = buf [k + l];
  4836.           while (ch != '\0' && ch != '\n' && ch != '\r') {
  4837.             l++;
  4838.             ch = buf [k + l];
  4839.           }
  4840.           if (ch == '\n' || ch == '\r') {
  4841.             buf [k + l] = '\0';
  4842.             if (Nlm_StringLen (buf + k) > 0) {
  4843.               Nlm_StaticPrompt (pg, buf + k, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4844.             }
  4845.             k += l + 1;
  4846.           } else {
  4847.             if (Nlm_StringLen (buf + k) > 0) {
  4848.               Nlm_StaticPrompt (pg, buf + k, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4849.             }
  4850.             k += l;
  4851.           }
  4852.         }
  4853.         hp [i] = (Nlm_Handle) Nlm_DialogText (g, curarg->defaultvalue, 10, NULL);
  4854.         if (firstText == NULL) {
  4855.           firstText = (Nlm_TexT) hp [i];
  4856.         }
  4857.         break;
  4858.       case ARG_FILE_IN:
  4859.       case ARG_FILE_OUT:
  4860.       case ARG_DATA_IN:
  4861.       case ARG_DATA_OUT:
  4862.         Nlm_StaticPrompt (g, curarg->prompt, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4863.         hp [i] = (Nlm_Handle) Nlm_DialogText (g, curarg->defaultvalue, 10, NULL);
  4864.         if (firstText == NULL) {
  4865.           firstText = (Nlm_TexT) hp [i];
  4866.         }
  4867.         break;
  4868.     }
  4869.     arg[0] = '\0';
  4870.     if ((curarg->from != NULL) || (curarg->to != NULL)) {
  4871.       tmp = Nlm_StringMove(arg, " (");
  4872.       tmp = Nlm_StringMove(tmp, curarg->from);
  4873.       if ((curarg->type == ARG_INT) || (curarg->type == ARG_FLOAT)) {
  4874.         tmp = Nlm_StringMove(tmp, " to ");
  4875.         tmp = Nlm_StringMove(tmp, curarg->to);
  4876.       }
  4877.       Nlm_StringMove(tmp, ")");
  4878.     } else {
  4879.       arg[0] = '\0';
  4880.     }
  4881.     if (curarg->type == ARG_FILE_IN) {
  4882.       Nlm_PushButton (g, "File IN", Nlm_GetArgsFileInProc);
  4883.     } else if (curarg->type == ARG_FILE_OUT) {
  4884.       Nlm_PushButton (g, "File OUT", Nlm_GetArgsFileOutProc);
  4885.     } else {
  4886.       Nlm_StaticPrompt(g, arg, 0,  Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4887.     }
  4888.   }
  4889.  
  4890.   Nlm_Break (w);
  4891.   h = Nlm_HiddenGroup (w, 10, 0, NULL);
  4892.   Nlm_PushButton (h, "OK", Nlm_GetArgsOkProc);
  4893.   Nlm_PushButton (h, "Cancel", Nlm_GetArgsCancelProc);
  4894.   Nlm_GetRect ((Nlm_GraphiC) g, &r1);
  4895.   Nlm_DoGetPosition ((Nlm_GraphiC) h, &r2);
  4896.   delta = (r1.right - r2.right);
  4897.   if (delta > 0) {
  4898.     Nlm_OffsetRect (&r2, delta / 2, 0);
  4899.     Nlm_DoSetPosition ((Nlm_GraphiC) h, &r2, TRUE);
  4900.   }
  4901.   Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  4902.   if (firstText != NULL) {
  4903.     Nlm_DoSelect ((Nlm_GraphiC) firstText, TRUE);
  4904.   }
  4905.   getArgsBoxUp = TRUE;
  4906.   while (getArgsBoxUp) {
  4907.     getArgsOk = FALSE;
  4908.     while (getArgsBoxUp) {
  4909.       Nlm_ProcessEventOrIdle ();
  4910.     }
  4911.  
  4912.     if (getArgsOk) {
  4913.       curarg = ap;
  4914.       for (i = 0; ((i < numargs) && (getArgsBoxUp == FALSE)); i++, curarg++) {
  4915.         resolved [i] = TRUE;
  4916.         switch (curarg->type) {
  4917.           case ARG_BOOLEAN:
  4918.             if (Nlm_GetStatus (hp [i])) {
  4919.               curarg->intvalue = 1;
  4920.             } else {
  4921.               curarg->intvalue = 0;
  4922.             }
  4923.             break;
  4924.           case ARG_INT:
  4925.             Nlm_GetTitle (hp [i], arg, sizeof (arg));
  4926.             sscanf(arg, "%ld", &curarg->intvalue);
  4927.             if ((curarg->from != NULL) || (curarg->to != NULL)) {
  4928.               range = TRUE;
  4929.               if (curarg->from != NULL) {
  4930.                 sscanf(curarg->from, "%ld", &ifrom);
  4931.                 if (curarg->intvalue < ifrom) {
  4932.                   range = FALSE;
  4933.                 }
  4934.               }
  4935.               if (curarg->to != NULL) {
  4936.                 sscanf(curarg->to, "%ld", &ito);
  4937.                 if (curarg->intvalue > ito) {
  4938.                   range = FALSE;
  4939.                 }
  4940.               }
  4941.               if (! range) {
  4942.                 if (curarg->from != NULL && curarg->to != NULL) {
  4943.                   Message(MSG_ERROR, "%s [%ld] is out of range [%ld to %ld]",
  4944.                           curarg->prompt, curarg->intvalue, ifrom, ito);
  4945.                 } else if (curarg->from != NULL) {
  4946.                   Message(MSG_ERROR, "%s [%ld] is out of range [%ld to ...]",
  4947.                           curarg->prompt, curarg->intvalue, ifrom);
  4948.                 } else if (curarg->to != NULL) {
  4949.                   Message(MSG_ERROR, "%s [%ld] is out of range [... to %ld]",
  4950.                           curarg->prompt, curarg->intvalue, ito);
  4951.                 }
  4952.                 getArgsBoxUp = TRUE;
  4953.                 Nlm_DoSelect ((Nlm_GraphiC) hp[i], TRUE);
  4954.               }
  4955.             }
  4956.             break;
  4957.           case ARG_FLOAT:
  4958.             Nlm_GetTitle (hp [i], arg, sizeof (arg));
  4959.             sscanf(arg, "%lf", &curarg->floatvalue);
  4960.             if ((curarg->from != NULL) || (curarg->to != NULL)) {
  4961.               range = TRUE;
  4962.               if (curarg->from != NULL) {
  4963.                 sscanf(curarg->from, "%lf", &ffrom);
  4964.                 if (curarg->floatvalue < ffrom) {
  4965.                   range = FALSE;
  4966.                 }
  4967.               }
  4968.               if (curarg->to != NULL) {
  4969.                 sscanf(curarg->to, "%lf", &fto);
  4970.                 if (curarg->floatvalue > fto) {
  4971.                   range = FALSE;
  4972.                 }
  4973.               }
  4974.               if (! range) {
  4975.                 if (curarg->from != NULL && curarg->to != NULL) {
  4976.                   Message(MSG_ERROR, "%s [%g] is out of range [%g to %g]",
  4977.                           curarg->prompt, curarg->floatvalue, ffrom, fto);
  4978.                 } else if (curarg->from != NULL) {
  4979.                   Message(MSG_ERROR, "%s [%g] is out of range [%g to ...]",
  4980.                           curarg->prompt, curarg->floatvalue, ffrom);
  4981.                 } else if (curarg->to != NULL) {
  4982.                   Message(MSG_ERROR, "%s [%g] is out of range [... to %g]",
  4983.                           curarg->prompt, curarg->floatvalue, fto);
  4984.                 }
  4985.                 Nlm_DoSelect ((Nlm_GraphiC) hp[i], TRUE);
  4986.                 getArgsBoxUp = TRUE;
  4987.               }
  4988.             }
  4989.             break;
  4990.           case ARG_STRING:
  4991.           case ARG_FILE_IN:
  4992.           case ARG_FILE_OUT:
  4993.           case ARG_DATA_IN:
  4994.           case ARG_DATA_OUT:
  4995.             Nlm_GetTitle (hp [i], arg, sizeof (arg));
  4996.             if (arg [0] != '\0') {
  4997.               curarg->strvalue = StringSave (arg);
  4998.             } else {
  4999.               curarg->strvalue = NULL;
  5000.             }
  5001.             break;
  5002.         }
  5003.       }
  5004.  
  5005.       curarg = ap;
  5006.       if (! getArgsBoxUp) {
  5007.         for (i = 0; i < numargs; i++, curarg++) {
  5008.           if ((! curarg->optional) && (! resolved[i])) {
  5009.             Message(MSG_ERROR, "%s was not given an argument", curarg->prompt);
  5010.             getArgsBoxUp = TRUE;
  5011.             Nlm_DoSelect ((Nlm_GraphiC) hp[i], TRUE);
  5012.             break;
  5013.           }
  5014.         }
  5015.       }
  5016.     }
  5017.   }  
  5018.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  5019.   Nlm_Update ();
  5020.  
  5021.   if (getArgsOk) {  /* leave up a little window with the program name */
  5022.     Nlm_StringMove(arg, progname);
  5023.     w = Nlm_FixedWindow (-50, -33, -10, -10, arg, NULL);
  5024.     Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  5025.   }
  5026.   return getArgsOk;
  5027. }
  5028.  
  5029. extern void Nlm_FreeWindows (void)
  5030.  
  5031. {
  5032.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
  5033. }
  5034.  
  5035. extern void Nlm_InitWindows (void)
  5036.  
  5037. {
  5038.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 11);
  5039.  
  5040. #ifdef DCLAP
  5041.     gProgramPath[0]= 0;
  5042.     gProgramName[0]= 0;
  5043. #endif
  5044.  
  5045.   documentProcs = &(gphprcsptr [0]);
  5046. #ifdef WIN_MAC
  5047.   documentProcs->click = Nlm_DocumentClick;
  5048.   documentProcs->key = Nlm_NormalKey;
  5049.   documentProcs->draw = Nlm_DocumentDraw;
  5050.   documentProcs->idle = Nlm_NormalIdle;
  5051. #endif
  5052.   documentProcs->show = Nlm_ShowDocument;
  5053.   documentProcs->hide = Nlm_HideWindow;
  5054.   documentProcs->activate = Nlm_DocumentActivate;
  5055.   documentProcs->deactivate = Nlm_DocumentDeactivate;
  5056.   documentProcs->remove = Nlm_RemoveWindow;
  5057.   documentProcs->select = Nlm_NormalSelect;
  5058.   documentProcs->linkIn = Nlm_LinkIn;
  5059.   documentProcs->adjustPrnt = Nlm_AdjustWindow;
  5060.   documentProcs->setTitle = Nlm_SetWindowTitle;
  5061.   documentProcs->getTitle = Nlm_GetWindowTitle;
  5062.   documentProcs->gainFocus = Nlm_WindowGainFocus;
  5063.   documentProcs->loseFocus = Nlm_WindowLoseFocus;
  5064.   documentProcs->sendChar = Nlm_NormalDrawChar;
  5065.  
  5066.   fixedProcs = &(gphprcsptr [1]);
  5067. #ifdef WIN_MAC
  5068.   fixedProcs->click = Nlm_DialogClick;
  5069.   fixedProcs->key = Nlm_NormalKey;
  5070.   fixedProcs->draw = Nlm_NormalDraw;
  5071.   fixedProcs->idle = Nlm_NormalIdle;
  5072. #endif
  5073.   fixedProcs->show = Nlm_ShowNormal;
  5074.   fixedProcs->hide = Nlm_HideWindow;
  5075.   fixedProcs->activate = Nlm_NormalActivate;
  5076.   fixedProcs->deactivate = Nlm_NormalDeactivate;
  5077.   fixedProcs->remove = Nlm_RemoveWindow;
  5078.   fixedProcs->select = Nlm_NormalSelect;
  5079.   fixedProcs->countItems = NULL;
  5080.   fixedProcs->linkIn = Nlm_LinkIn;
  5081.   fixedProcs->adjustPrnt = Nlm_AdjustWindow;
  5082.   fixedProcs->setTitle = Nlm_SetWindowTitle;
  5083.   fixedProcs->getTitle = Nlm_GetWindowTitle;
  5084.   fixedProcs->gainFocus = Nlm_WindowGainFocus;
  5085.   fixedProcs->loseFocus = Nlm_WindowLoseFocus;
  5086.   fixedProcs->sendChar = Nlm_NormalDrawChar;
  5087.  
  5088.   frozenProcs = &(gphprcsptr [2]);
  5089. #ifdef WIN_MAC
  5090.   frozenProcs->click = Nlm_FrozenClick;
  5091.   frozenProcs->key = Nlm_NormalKey;
  5092.   frozenProcs->draw = Nlm_NormalDraw;
  5093.   frozenProcs->idle = Nlm_NormalIdle;
  5094. #endif
  5095.   frozenProcs->show = Nlm_ShowNormal;
  5096.   frozenProcs->hide = Nlm_HideWindow;
  5097.   frozenProcs->activate = Nlm_NormalActivate;
  5098.   frozenProcs->deactivate = Nlm_NormalDeactivate;
  5099.   frozenProcs->remove = Nlm_RemoveWindow;
  5100.   frozenProcs->select = Nlm_NormalSelect;
  5101.   frozenProcs->linkIn = Nlm_LinkIn;
  5102.   frozenProcs->adjustPrnt = Nlm_AdjustWindow;
  5103.   frozenProcs->setTitle = Nlm_SetWindowTitle;
  5104.   frozenProcs->getTitle = Nlm_GetWindowTitle;
  5105.   frozenProcs->gainFocus = Nlm_WindowGainFocus;
  5106.   frozenProcs->loseFocus = Nlm_WindowLoseFocus;
  5107.   frozenProcs->sendChar = Nlm_NormalDrawChar;
  5108.  
  5109.   roundProcs = &(gphprcsptr [3]);
  5110. #ifdef WIN_MAC
  5111.   roundProcs->click = Nlm_DialogClick;
  5112.   roundProcs->key = Nlm_NormalKey;
  5113.   roundProcs->draw = Nlm_NormalDraw;
  5114.   roundProcs->idle = Nlm_NormalIdle;
  5115. #endif
  5116.   roundProcs->show = Nlm_ShowNormal;
  5117.   roundProcs->hide = Nlm_HideWindow;
  5118.   roundProcs->activate = Nlm_NormalActivate;
  5119.   roundProcs->deactivate = Nlm_NormalDeactivate;
  5120.   roundProcs->remove = Nlm_RemoveWindow;
  5121.   roundProcs->select = Nlm_NormalSelect;
  5122.   roundProcs->linkIn = Nlm_LinkIn;
  5123.   roundProcs->adjustPrnt = Nlm_AdjustWindow;
  5124.   roundProcs->setTitle = Nlm_SetWindowTitle;
  5125.   roundProcs->getTitle = Nlm_GetWindowTitle;
  5126.   roundProcs->gainFocus = Nlm_WindowGainFocus;
  5127.   roundProcs->loseFocus = Nlm_WindowLoseFocus;
  5128.   roundProcs->sendChar = Nlm_NormalDrawChar;
  5129.  
  5130.   alertProcs = &(gphprcsptr [4]);
  5131. #ifdef WIN_MAC
  5132.   alertProcs->click = Nlm_PlainClick;
  5133.   alertProcs->key = Nlm_NormalKey;
  5134.   alertProcs->draw = Nlm_NormalDraw;
  5135.   alertProcs->idle = Nlm_NormalIdle;
  5136. #endif
  5137.   alertProcs->show = Nlm_ShowNormal;
  5138.   alertProcs->hide = Nlm_HideWindow;
  5139.   alertProcs->activate = Nlm_NormalActivate;
  5140.   alertProcs->deactivate = Nlm_NormalDeactivate;
  5141.   alertProcs->remove = Nlm_RemoveWindow;
  5142.   alertProcs->select = Nlm_PlainSelect;
  5143.   alertProcs->linkIn = Nlm_LinkIn;
  5144.   alertProcs->adjustPrnt = Nlm_AdjustWindow;
  5145.   alertProcs->setTitle = Nlm_SetWindowTitle;
  5146.   alertProcs->getTitle = Nlm_GetWindowTitle;
  5147.   alertProcs->gainFocus = Nlm_WindowGainFocus;
  5148.   alertProcs->loseFocus = Nlm_WindowLoseFocus;
  5149.   alertProcs->sendChar = Nlm_NormalDrawChar;
  5150.  
  5151.   modalProcs = &(gphprcsptr [5]);
  5152. #ifdef WIN_MAC
  5153.   modalProcs->click = Nlm_ModalClick;
  5154.   modalProcs->key = Nlm_ModalKey;
  5155.   modalProcs->draw = Nlm_NormalDraw;
  5156.   modalProcs->idle = Nlm_NormalIdle;
  5157. #endif
  5158.   modalProcs->show = Nlm_ShowModal;
  5159.   modalProcs->hide = Nlm_HideModal;
  5160.   modalProcs->activate = Nlm_NormalActivate;
  5161.   modalProcs->deactivate = Nlm_NormalDeactivate;
  5162.   modalProcs->remove = Nlm_RemoveWindow;
  5163.   modalProcs->select = Nlm_PlainSelect;
  5164.   modalProcs->linkIn = Nlm_LinkIn;
  5165.   modalProcs->adjustPrnt = Nlm_AdjustWindow;
  5166.   modalProcs->setTitle = Nlm_SetWindowTitle;
  5167.   modalProcs->getTitle = Nlm_GetWindowTitle;
  5168.   modalProcs->gainFocus = Nlm_WindowGainFocus;
  5169.   modalProcs->loseFocus = Nlm_WindowLoseFocus;
  5170.   modalProcs->sendChar = Nlm_NormalDrawChar;
  5171.  
  5172.   floatingProcs = &(gphprcsptr [6]);
  5173. #ifdef WIN_MAC
  5174.   floatingProcs->click = Nlm_FloatingClick;
  5175.   floatingProcs->key = Nlm_FloatingKey;
  5176.   floatingProcs->draw = Nlm_NormalDraw;
  5177.   floatingProcs->idle = Nlm_FloatingIdle;
  5178. #endif
  5179.   floatingProcs->show = Nlm_ShowNormal;
  5180.   floatingProcs->hide = Nlm_HideWindow;
  5181.   floatingProcs->activate = Nlm_NormalActivate;
  5182.   floatingProcs->deactivate = Nlm_NormalDeactivate;
  5183.   floatingProcs->remove = Nlm_RemoveWindow;
  5184.   floatingProcs->select = Nlm_FloatingSelect;
  5185.   floatingProcs->linkIn = Nlm_LinkIn;
  5186.   floatingProcs->adjustPrnt = Nlm_AdjustWindow;
  5187.   floatingProcs->setTitle = Nlm_SetWindowTitle;
  5188.   floatingProcs->getTitle = Nlm_GetWindowTitle;
  5189.   floatingProcs->gainFocus = Nlm_WindowGainFocus;
  5190.   floatingProcs->loseFocus = Nlm_WindowLoseFocus;
  5191.   floatingProcs->sendChar = Nlm_FloatingDrawChar;
  5192.  
  5193.   shadowProcs = &(gphprcsptr [7]);
  5194. #ifdef WIN_MAC
  5195.   shadowProcs->click = Nlm_PlainClick;
  5196.   shadowProcs->key = Nlm_NormalKey;
  5197.   shadowProcs->draw = Nlm_NormalDraw;
  5198.   shadowProcs->idle = Nlm_NormalIdle;
  5199. #endif
  5200.   shadowProcs->show = Nlm_ShowNormal;
  5201.   shadowProcs->hide = Nlm_HideWindow;
  5202.   shadowProcs->activate = Nlm_NormalActivate;
  5203.   shadowProcs->deactivate = Nlm_NormalDeactivate;
  5204.   shadowProcs->remove = Nlm_RemoveWindow;
  5205.   shadowProcs->select = Nlm_PlainSelect;
  5206.   shadowProcs->linkIn = Nlm_LinkIn;
  5207.   shadowProcs->adjustPrnt = Nlm_AdjustWindow;
  5208.   shadowProcs->setTitle = Nlm_SetWindowTitle;
  5209.   shadowProcs->getTitle = Nlm_GetWindowTitle;
  5210.   shadowProcs->gainFocus = Nlm_WindowGainFocus;
  5211.   shadowProcs->loseFocus = Nlm_WindowLoseFocus;
  5212.   shadowProcs->sendChar = Nlm_NormalDrawChar;
  5213.  
  5214.   plainProcs = &(gphprcsptr [8]);
  5215. #ifdef WIN_MAC
  5216.   plainProcs->click = Nlm_PlainClick;
  5217.   plainProcs->key = Nlm_NormalKey;
  5218.   plainProcs->draw = Nlm_NormalDraw;
  5219.   plainProcs->idle = Nlm_NormalIdle;
  5220. #endif
  5221.   plainProcs->show = Nlm_ShowNormal;
  5222.   plainProcs->hide = Nlm_HideWindow;
  5223.   plainProcs->activate = Nlm_NormalActivate;
  5224.   plainProcs->deactivate = Nlm_NormalDeactivate;
  5225.   plainProcs->remove = Nlm_RemoveWindow;
  5226.   plainProcs->select = Nlm_PlainSelect;
  5227.   plainProcs->linkIn = Nlm_LinkIn;
  5228.   plainProcs->adjustPrnt = Nlm_AdjustWindow;
  5229.   plainProcs->setTitle = Nlm_SetWindowTitle;
  5230.   plainProcs->getTitle = Nlm_GetWindowTitle;
  5231.   plainProcs->gainFocus = Nlm_WindowGainFocus;
  5232.   plainProcs->loseFocus = Nlm_WindowLoseFocus;
  5233.   plainProcs->sendChar = Nlm_NormalDrawChar;
  5234.  
  5235.   desktopProcs = &(gphprcsptr [9]);
  5236. #ifdef WIN_MAC
  5237.   desktopProcs->click = Nlm_DesktopClick;
  5238.   desktopProcs->key = Nlm_DesktopKey;
  5239. #endif
  5240.   desktopProcs->show = Nlm_ShowNormal;
  5241.   desktopProcs->hide = Nlm_HideWindow;
  5242.   desktopProcs->remove = Nlm_RemoveWindow;
  5243.   desktopProcs->select = Nlm_DesktopSelect;
  5244.   desktopProcs->linkIn = Nlm_LinkIn;
  5245.  
  5246.   systemProcs = &(gphprcsptr [10]);
  5247. #ifdef WIN_MAC
  5248.   systemProcs->click = Nlm_SystemClick;
  5249.   systemProcs->draw = Nlm_NormalDraw;
  5250. #endif
  5251.   systemProcs->show = Nlm_ShowNormal;
  5252.   systemProcs->hide = Nlm_HideWindow;
  5253.   systemProcs->remove = Nlm_RemoveWindow;
  5254.   systemProcs->select = Nlm_NormalSelect;
  5255.   systemProcs->linkIn = Nlm_LinkIn;
  5256. }
  5257.